Skip to contentSkip to conversation

auxdisplay: ht16k33: Add character display support

PATCH Applied Geert Uytterhoeven 2 participants 27 messages Oct 19, 2021 – Oct 21, 2021

Subsystems (6)
lore
Share & tools
lore

Geert Uytterhoeven

author reviewer
#0 lore raw

v8 cover auxdisplay: ht16k33: Add character display support

Hi Miguel et al,

The Holtek HT16K33 LED controller is not only used for driving dot-matrix displays, but also for driving segment displays. The current auxdisplay driver is limited to dot-matrix displays, which are exposed as a frame buffer device.

This patch series extends the driver to 4-digit 7-segment and quad 14-segment alphanumeric displays, allowing the user to display and scroll text messages.

List of patches:
- Patch 1 provides font data for displaying ASCII characters on 14-segment displays,
- Patch 2 updates the HT16K33 DT bindings for segment displays,
- Patches 3-5 contain a bug fix and small improvements for the Imagination Technologies ASCII LCD Display driver,
- Patch 6 extracts the character line display core support from the Imagination Technologies ASCII LCD Display driver, for reuse,
- Patches 7-8 contain cleanups and improvements for the character line display core driver,
- Patches 9-17 contain a bug fixes, cleanups and improvements for the HT16K33 driver, to prepare for segment display support,
- Patch 18 adds support for 7/14-segment displays to the HT16K33 driver,
- Patch 19 updates the HT16K33 DT bindings to document an LED subnode,
- Patch 20 adds segment display LED support to the HT16K33 driver, to make use of hardware blinking, and to expose display color,
- Patch 21 converts the HT16K33 driver to use device properties.

Changes compared to v7[1]:
- Fix array upper bound check in map_to_seg14(),
- Add Reviewed-by, Acked-by.

Changes compared to v6[2]:
- Add Acked-by, Reviewed-by,
- New patch "auxdisplay: ht16k33: Fix frame buffer device blanking",
- Add linux,default-trigger to example,
- Add missing call to ht16k33_brightness_set() in ht16k33_fbdev_probe(), to make sure brightness and blinking are set to a sane state,
- Integrate "auxdisplay: ht16k33: Make use of device properties" into this series.

Changes compared to v5[3]:
- Add Reviewed-by,
- Reorder operations in ht16k33_led_probe() to ease future conversion to device properties.

Changes compared to v4[4]:
- Add Reviewed-by,
- Add missing select NEW_LEDS.

Changes compared to v3[5]:
- Combine compatible values for 7/14 segment displays into an enum,
- Add Reviewed-by,
- Add missing select LEDS_CLASS.

Changes compared to v2[6]:
- Drop color property from display node,
- Use compat_only_sysfs_link_entry_to_kobj() instead of cooking our own helper on top of kernfs_create_link(),
- Use "err" instead of "error" to be consistent with existing driver naming style,
- Pass "dev" instead of "client" to ht16k33_fbdev_probe() and

    ht16k33_seg_probe(),

- Drop local variable "node",
- Remove unneeded inclusion of <linux/leds.h> and <linux/of_device.h>,
- Document LED subnode,
- Remove unneeded C++ comment,
- Make the creation of the LED device dependent on the presence of the "led" subnode in DT, so it can be used in dot-matrix mode too.
- Use led_init_data() and devm_led_classdev_register_ext() to retrieve all LED properties from DT, instead of manual LED name construction based on just the "color" property.

Changes compared to v1[7]:
- Fix type of color to uint32,
- "refresh-rate-hz" is still required for dot-matrix displays.
- Move "select LINEDISP" for HT16K33 symbol to correct patch,
- Add backwards compatibility "message" symlink to img-ascii-lcd,
- Connect backlight to fbdev in ht16k33 dot-matrix mode,
- Set "err = -EINVAL" in switch() case that cannot happen,
- Use "auxdisplay" instead of DRIVER_NAME in LED name.

This series has been tested using an Adafruit 0.54" Quad Alphanumeric Red FeatherWing Display, connected to an OrangeCrab ECP5 FPGA board running a 64 MHz VexRiscv RISC-V softcore.
7-segment display support is based purely on schematics, and has not been tested on actual hardware. The changes to img-ascii-lcd.c are also untested, due to lack of hardware.

Thanks for applying!

[1] "[PATCH v7 00/21] auxdisplay: ht16k33: Add character display support"

    https://lore.kernel.org/r/[email protected]/
[2] "[PATCH v6 00/19] auxdisplay: ht16k33: Add character display support"
    https://lore.kernel.org/r/[email protected]/
[3] "[PATCH v5 00/19] auxdisplay: ht16k33: Add character display support"
    https://lore.kernel.org/r/[email protected]/
[3] "[PATCH v4 00/19] auxdisplay: ht16k33: Add character display support"
    https://lore.kernel.org/r/[email protected]/
[4] "[PATCH v3 00/19] auxdisplay: ht16k33: Add character display support"
    https://lore.kernel.org/r/[email protected]/
[5] "[PATCH v2 00/18] auxdisplay: ht16k33: Add character display support"
    https://lore.kernel.org/r/[email protected]/
[6] "[PATCH 00/17] auxdisplay: ht16k33: Add character display support"
    https://lore.kernel.org/r/[email protected]/

Geert Uytterhoeven (21):
uapi: Add <linux/map_to_14segment.h>
dt-bindings: auxdisplay: ht16k33: Document Adafruit segment displays
auxdisplay: img-ascii-lcd: Fix lock-up when displaying empty string
auxdisplay: img-ascii-lcd: Add helper variable dev
auxdisplay: img-ascii-lcd: Convert device attribute to sysfs_emit()
auxdisplay: Extract character line display core support
auxdisplay: linedisp: Use kmemdup_nul() helper
auxdisplay: linedisp: Add support for changing scroll rate
auxdisplay: ht16k33: Connect backlight to fbdev
auxdisplay: ht16k33: Fix frame buffer device blanking
auxdisplay: ht16k33: Use HT16K33_FB_SIZE in ht16k33_initialize()
auxdisplay: ht16k33: Remove unneeded error check in keypad probe()
auxdisplay: ht16k33: Convert to simple i2c probe function
auxdisplay: ht16k33: Add helper variable dev
auxdisplay: ht16k33: Move delayed work
auxdisplay: ht16k33: Extract ht16k33_brightness_set()
auxdisplay: ht16k33: Extract frame buffer probing
auxdisplay: ht16k33: Add support for segment displays
dt-bindings: auxdisplay: ht16k33: Document LED subnode
auxdisplay: ht16k33: Add LED support
auxdisplay: ht16k33: Make use of device properties

 .../bindings/auxdisplay/holtek,ht16k33.yaml   |  32 +-
 drivers/auxdisplay/Kconfig                    |  12 +-
 drivers/auxdisplay/Makefile                   |   1 +
 drivers/auxdisplay/ht16k33.c                  | 500 ++++++++++++++----
 drivers/auxdisplay/img-ascii-lcd.c            | 205 ++-----
 drivers/auxdisplay/line-display.c             | 261 +++++++++
 drivers/auxdisplay/line-display.h             |  43 ++
 include/uapi/linux/map_to_14segment.h         | 241 +++++++++
 8 files changed, 1019 insertions(+), 276 deletions(-)
 create mode 100644 drivers/auxdisplay/line-display.c
 create mode 100644 drivers/auxdisplay/line-display.h
 create mode 100644 include/uapi/linux/map_to_14segment.h
Signature · 12 lines
2.25.1

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds
author reviewer
#1 lore raw

PATCH v8 1/21 uapi: Add <linux/map_to_14segment.h>

Add a header file providing translation primitives and tables for the conversion of (ASCII) characters to a 14-segments notation, as used by 14-segment alphanumeric displays.

This follows the spirit of include/uapi/linux/map_to_7segment.h.

---
v8:
- Fix array upper bound check in map_to_seg14(),

v7:
- No changes,

v6:
- No changes,

v5:
- No changes,

v4:
- No changes,

v3:
- No changes,

v2:
- No changes.

You can find an image of the full character set at
https://drive.google.com/file/d/1h3EYFBWHIjh8B_cwPA5ocAD-lFYipRie/view

Note that all non-empty characters are unique, except for "[" and "C", and "|" and ":".

---
 include/uapi/linux/map_to_14segment.h | 241 ++++++++++++++++++++++++++
 1 file changed, 241 insertions(+)
 create mode 100644 include/uapi/linux/map_to_14segment.h
include/uapi/linux/map_to_14segment.h new file +241 -0
new file mode 100644
index 0000000000000000..0346ef76543b1973
@@ -0,0 +1,241 @@
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+/*
+ * Copyright (C) 2021 Glider bv
+ *
+ * Based on include/uapi/linux/map_to_7segment.h:
+
+ * Copyright (c) 2005 Henk Vergonet <[email protected]>
+ */
+
+#ifndef MAP_TO_14SEGMENT_H
+#define MAP_TO_14SEGMENT_H
+
+/* This file provides translation primitives and tables for the conversion
+ * of (ASCII) characters to a 14-segments notation.
+ *
+ * The 14 segment's wikipedia notation below is used as standard.
+ * See: https://en.wikipedia.org/wiki/Fourteen-segment_display
+ *
+ * Notation:	+---a---+
+ *		|\  |  /|
+ *		f h i j b
+ *		|  \|/  |
+ *		+-g1+-g2+
+ *		|  /|\  |
+ *		e k l m c
+ *		|/  |  \|
+ *		+---d---+
+ *
+ * Usage:
+ *
+ *   Register a map variable, and fill it with a character set:
+ *	static SEG14_DEFAULT_MAP(map_seg14);
+ *
+ *
+ *   Then use for conversion:
+ *	seg14 = map_to_seg14(&map_seg14, some_char);
+ *	...
+ *
+ * In device drivers it is recommended, if required, to make the char map
+ * accessible via the sysfs interface using the following scheme:
+ *
+ * static ssize_t map_seg14_show(struct device *dev,
+ *				 struct device_attribute *attr, char *buf)
+ * {
+ *	memcpy(buf, &map_seg14, sizeof(map_seg14));
+ *	return sizeof(map_seg14);
+ * }
+ * static ssize_t map_seg14_store(struct device *dev,
+ *				  struct device_attribute *attr,
+ *				  const char *buf, size_t cnt)
+ * {
+ *	if (cnt != sizeof(map_seg14))
+ *		return -EINVAL;
+ *	memcpy(&map_seg14, buf, cnt);
+ *	return cnt;
+ * }
+ * static DEVICE_ATTR_RW(map_seg14);
+ */
+#include <linux/errno.h>
+#include <linux/types.h>
+
+#include <asm/byteorder.h>
+
+#define BIT_SEG14_A		0
+#define BIT_SEG14_B		1
+#define BIT_SEG14_C		2
+#define BIT_SEG14_D		3
+#define BIT_SEG14_E		4
+#define BIT_SEG14_F		5
+#define BIT_SEG14_G1		6
+#define BIT_SEG14_G2		7
+#define BIT_SEG14_H		8
+#define BIT_SEG14_I		9
+#define BIT_SEG14_J		10
+#define BIT_SEG14_K		11
+#define BIT_SEG14_L		12
+#define BIT_SEG14_M		13
+#define BIT_SEG14_RESERVED1	14
+#define BIT_SEG14_RESERVED2	15
+
+struct seg14_conversion_map {
+	__be16 table[128];
+};
+
+static __inline__ int map_to_seg14(struct seg14_conversion_map *map, int c)
+{
+	if (c < 0 || c >= sizeof(map->table) / sizeof(map->table[0]))
+		return -EINVAL;
+
+	return __be16_to_cpu(map->table[c]);
+}
+
+#define SEG14_CONVERSION_MAP(_name, _map)	\
+	struct seg14_conversion_map _name = { .table = { _map } }
+
+/*
+ * It is recommended to use a facility that allows user space to redefine
+ * custom character sets for LCD devices. Please use a sysfs interface
+ * as described above.
+ */
+#define MAP_TO_SEG14_SYSFS_FILE	"map_seg14"
+
+/*******************************************************************************
+ * ASCII conversion table
+ ******************************************************************************/
+
+#define _SEG14(sym, a, b, c, d, e, f, g1, g2, h, j, k, l, m, n)	\
+	__cpu_to_be16( a << BIT_SEG14_A  |  b << BIT_SEG14_B  |	\
+		       c << BIT_SEG14_C  |  d << BIT_SEG14_D  |	\
+		       e << BIT_SEG14_E  |  f << BIT_SEG14_F  |	\
+		      g1 << BIT_SEG14_G1 | g2 << BIT_SEG14_G2 |	\
+		       h << BIT_SEG14_H  |  j << BIT_SEG14_I  |	\
+		       k << BIT_SEG14_J  |  l << BIT_SEG14_K  |	\
+		       m << BIT_SEG14_L  |  n << BIT_SEG14_M )
+
+#define _MAP_0_32_ASCII_SEG14_NON_PRINTABLE				\
+	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+
+#define _MAP_33_47_ASCII_SEG14_SYMBOL				\
+	_SEG14('!', 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),	\
+	_SEG14('"', 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0),	\
+	_SEG14('#', 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0),	\
+	_SEG14('$', 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0),	\
+	_SEG14('%', 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0),	\
+	_SEG14('&', 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1),	\
+	_SEG14('\'',0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0),	\
+	_SEG14('(', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1),	\
+	_SEG14(')', 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0),	\
+	_SEG14('*', 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1),	\
+	_SEG14('+', 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0),	\
+	_SEG14(',', 0, 0, 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, 0, 0, 1),	\
+	_SEG14('t', 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0),	\
+	_SEG14('u', 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0),	\
+	_SEG14('v', 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0),	\
+	_SEG14('w', 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1),	\
+	_SEG14('x', 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1),	\
+	_SEG14('y', 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0),	\
+	_SEG14('z', 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0),
+
+#define _MAP_123_126_ASCII_SEG14_SYMBOL				\
+	_SEG14('{', 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0),	\
+	_SEG14('|', 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0),	\
+	_SEG14('}', 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1),	\
+	_SEG14('~', 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0),
+
+/* Maps */
+#define MAP_ASCII14SEG_ALPHANUM			\
+	_MAP_0_32_ASCII_SEG14_NON_PRINTABLE	\
+	_MAP_33_47_ASCII_SEG14_SYMBOL		\
+	_MAP_48_57_ASCII_SEG14_NUMERIC		\
+	_MAP_58_64_ASCII_SEG14_SYMBOL		\
+	_MAP_65_90_ASCII_SEG14_ALPHA_UPPER	\
+	_MAP_91_96_ASCII_SEG14_SYMBOL		\
+	_MAP_97_122_ASCII_SEG14_ALPHA_LOWER	\
+	_MAP_123_126_ASCII_SEG14_SYMBOL
+
+#define SEG14_DEFAULT_MAP(_name)		\
+	SEG14_CONVERSION_MAP(_name, MAP_ASCII14SEG_ALPHANUM)
+
+#endif	/* MAP_TO_14SEGMENT_H */
Signature · 1 line
2.25.1
author reviewer
#2 lore raw

PATCH v8 2/21 dt-bindings: auxdisplay: ht16k33: Document Adafruit segment displays

In reply to Geert Uytterhoeven

The Holtek HT16K33 LED controller is not only used for driving dot-matrix displays, but also for driving segment displays.

Document compatible values for the Adafruit 7-segment[1] and 14-segment[2] FeatherWing expansion boards with red displays. According to the schematics, all other Adafruit 7-segment and 14-segment display backpack and FeatherWing expansion boards (including bare boards and boards fitted with displays) are compatible with these two boards.

[1] https://www.adafruit.com/product/3108
[2] https://www.adafruit.com/product/3130

---
v8:
- No changes,

v7:
- No changes,

v6:
- No changes,

v5:
- Add Reviewed-by,

v4:
- Combine compatible values for 7/14 segment displays into an enum,

v3:
- Drop color property,

v2:
- Fix type of color to uint32,
- "refresh-rate-hz" is still required for dot-matrix displays.

Alternatives I considered:
1. Document the attached display type in a child node. I.e. specify segment type, number of characters, and wiring. Especially the latter would become really complex, due to the sheer amount of possible wiring combinations.
Using this method, you also loose the ability to just connect a display to an i2c bus, and instantiate the device from sysfs, without using DT:

echo adafruit,3130 0x70 > /sys/class/i2c/i2c-adapter/.../new_device

2. Document all Adafruit 7-segment and 14-segment display backpack and FeatherWing expansion boards.
This would lead to a myriad of compatible values:

- items:
- enum:
- adafruit,878 # 0.56" 4-Digit 7-Segment Display Backpack (Red)
- adafruit,879 # 0.56" 4-Digit 7-Segment Display Backpack (Yellow)
- adafruit,880 # 0.56" 4-Digit 7-Segment Display Backpack (Green)
- adafruit,881 # 0.56" 4-Digit 7-Segment Display Backpack (Blue)
- adafruit,1002 # 0.56" 4-Digit 7-Segment Display Backpack (White)
- const: adafruit,877 # 0.56" 4-Digit 7-Segment Backpack
- const: holtek,ht16k33

- items:
- enum:
- adafruit,1268 # 1.2" 4-Digit 7-Segment Display Backpack (Green)
- adafruit,1269 # 1.2" 4-Digit 7-Segment Display Backpack (Yellow)
- adafruit,1270 # 1.2" 4-Digit 7-Segment Display Backpack (Red)
- const: adafruit,1271 # 1.2" 4-Digit 7-Segment Backpack
- const: holtek,ht16k33

- items:
- enum:
- adafruit,1911 # 0.54" Quad Alphanumeric Display Backpack (Red)
- adafruit,1912 # 0.54" Quad Alphanumeric Display Backpack (Blue)
- adafruit,2157 # 0.54" Quad Alphanumeric Display Backpack (White)
- adafruit,2158 # 0.54" Quad Alphanumeric Display Backpack (Yellow)
- adafruit,2159 # 0.54" Quad Alphanumeric Display Backpack (Yellow-Green)
- adafruit,2160 # 0.54" Quad Alphanumeric Display Backpack (Green)
- const: adafruit,1910 # 0.54" Quad 14-segment Alphanumeric Backpack
- const: holtek,ht16k33

- items:
- enum:
- adafruit,3106 # 0.56" 4-Digit 7-Segment FeatherWing Display (Blue)
- adafruit,3107 # 0.56" 4-Digit 7-Segment FeatherWing Display (Green)
- adafruit,3108 # 0.56" 4-Digit 7-Segment FeatherWing Display (Red)
- adafruit,3109 # 0.56" 4-Digit 7-Segment FeatherWing Display (White)
- adafruit,3110 # 0.56" 4-Digit 7-Segment FeatherWing Display (Yellow)
- const: adafruit,3088 # 0.56" 4-Digit 7-Segment FeatherWing
- const: holtek,ht16k33

- items:
- enum:
- adafruit,3127 # 0.54" Quad Alphanumeric FeatherWing Display (White)
- adafruit,3128 # 0.54" Quad Alphanumeric FeatherWing Display (Blue)
- adafruit,3129 # 0.54" Quad Alphanumeric FeatherWing Display (Green)
- adafruit,3130 # 0.54" Quad Alphanumeric FeatherWing Display (Red)
- adafruit,3131 # 0.54" Quad Alphanumeric FeatherWing Display (Yellow)
- adafruit,3132 # 0.54" Quad Alphanumeric FeatherWing Display (Yellow-Green)
- const: adafruit,3089 # 0.54" Quad 14-segment Alphanumeric FeatherWing
- const: holtek,ht16k33

---
 .../bindings/auxdisplay/holtek,ht16k33.yaml   | 20 ++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/auxdisplay/holtek,ht16k33.yaml +17 -3
index 64ffff460026040f..6baf1200c9d8488e 100644
@@ -14,14 +14,21 @@ allOf:
 
 properties:
   compatible:
-    const: holtek,ht16k33
+    oneOf:
+      - items:
+          - enum:
+              - adafruit,3108  # 0.56" 4-Digit 7-Segment FeatherWing Display (Red)
+              - adafruit,3130  # 0.54" Quad Alphanumeric FeatherWing Display (Red)
+          - const: holtek,ht16k33
+
+      - const: holtek,ht16k33     # Generic 16*8 LED controller with dot-matrix display
 
   reg:
     maxItems: 1
 
   refresh-rate-hz:
     maxItems: 1
-    description: Display update interval in Hertz
+    description: Display update interval in Hertz for dot-matrix displays
 
   interrupts:
     maxItems: 1
@@ -44,7 +51,14 @@ properties:
 required:
   - compatible
   - reg
-  - refresh-rate-hz
+
+if:
+  properties:
+    compatible:
+      const: holtek,ht16k33
+then:
+  required:
+    - refresh-rate-hz
 
 additionalProperties: false
 
Signature · 1 line
2.25.1
author reviewer
#3 lore raw

PATCH v8 3/21 auxdisplay: img-ascii-lcd: Fix lock-up when displaying empty string

In reply to Geert Uytterhoeven

While writing an empty string to a device attribute is a no-op, and thus does not need explicit safeguards, the user can still write a single newline to an attribute file:

    echo > .../message

If that happens, img_ascii_lcd_display() trims the newline, yielding an empty string, and causing an infinite loop in img_ascii_lcd_scroll().

Fix this by adding a check for empty strings. Clear the display in case one is encountered.

Fixes 0cad855fbd083ee5 ("auxdisplay: img-ascii-lcd: driver for simple ASCII LCD displays")

---
Untested with img-ascii-lcd, but triggered with my initial version of linedisp.

v8:
- No changes,

v7:
- No changes,

v6:
- No changes,

v5:
- No changes,

v4:
- No changes,

v3:
- No changes,

v2:
- No changes.

---
 drivers/auxdisplay/img-ascii-lcd.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/auxdisplay/img-ascii-lcd.c +10 -0
index 1cce409ce5cacbc8..e33ce0151cdfd150 100644
@@ -280,6 +280,16 @@ static int img_ascii_lcd_display(struct img_ascii_lcd_ctx *ctx,
 	if (msg[count - 1] == '\n')
 		count--;
 
+	if (!count) {
+		/* clear the LCD */
+		devm_kfree(&ctx->pdev->dev, ctx->message);
+		ctx->message = NULL;
+		ctx->message_len = 0;
+		memset(ctx->curr, ' ', ctx->cfg->num_chars);
+		ctx->cfg->update(ctx);
+		return 0;
+	}
+
 	new_msg = devm_kmalloc(&ctx->pdev->dev, count + 1, GFP_KERNEL);
 	if (!new_msg)
 		return -ENOMEM;
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH v8 03/21] auxdisplay: img-ascii-lcd: Fix lock-up when displaying empty string

Quoted 2 lines · Geert Uytterhoeven

+ devm_kfree(&ctx->pdev->dev, ctx->message);

Unrelated to this patch (and no need to change it), but we could remove the conditional guarding the devm_kfree below to match this one.

Cheers,
Miguel

#5 lore raw

Re: [PATCH v8 03/21] auxdisplay: img-ascii-lcd: Fix lock-up when displaying empty string

Quoted 4 lines · Miguel Ojeda

Unrelated to this patch (and no need to change it), but we could remove the conditional guarding the devm_kfree below to match this one.

Yeah, you did it when moving the code later on -- I guess we could have done it before too, to match, like the sysfs_emit change does it before, but it is not that important.

Cheers,
Miguel

author reviewer
#6 lore raw

Re: [PATCH v8 03/21] auxdisplay: img-ascii-lcd: Fix lock-up when displaying empty string

Hi Miguel,

Quoted 10 lines · Miguel Ojeda
Quoted 4 lines · Miguel Ojeda

Unrelated to this patch (and no need to change it), but we could remove the conditional guarding the devm_kfree below to match this one.

Yeah, you did it when moving the code later on -- I guess we could have done it before too, to match, like the sysfs_emit change does it before, but it is not that important.

As this patch fixes a DoS that can be triggered from userspace, I wanted it to be a fix as small and concise as possible.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author reviewer
#7 lore raw

PATCH v8 4/21 auxdisplay: img-ascii-lcd: Add helper variable dev

In reply to Geert Uytterhoeven

img_ascii_lcd_probe() has many users of "pdev->dev". Add a shorthand to simplify the code.

---
v8:
- No changes,

v7:
- No changes,

v6:
- No changes,

v5:
- No changes,

v4:
- No changes,

v3:
- No changes,

v2:
- No changes.

---
 drivers/auxdisplay/img-ascii-lcd.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/auxdisplay/img-ascii-lcd.c +6 -7
index e33ce0151cdfd150..2b6e41ec57544faa 100644
@@ -365,26 +365,25 @@ static int img_ascii_lcd_probe(struct platform_device *pdev)
 {
 	const struct of_device_id *match;
 	const struct img_ascii_lcd_config *cfg;
+	struct device *dev = &pdev->dev;
 	struct img_ascii_lcd_ctx *ctx;
 	int err;
 
-	match = of_match_device(img_ascii_lcd_matches, &pdev->dev);
+	match = of_match_device(img_ascii_lcd_matches, dev);
 	if (!match)
 		return -ENODEV;
 
 	cfg = match->data;
-	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx) + cfg->num_chars,
-			   GFP_KERNEL);
+	ctx = devm_kzalloc(dev, sizeof(*ctx) + cfg->num_chars, GFP_KERNEL);
 	if (!ctx)
 		return -ENOMEM;
 
 	if (cfg->external_regmap) {
-		ctx->regmap = syscon_node_to_regmap(pdev->dev.parent->of_node);
+		ctx->regmap = syscon_node_to_regmap(dev->parent->of_node);
 		if (IS_ERR(ctx->regmap))
 			return PTR_ERR(ctx->regmap);
 
-		if (of_property_read_u32(pdev->dev.of_node, "offset",
-					 &ctx->offset))
+		if (of_property_read_u32(dev->of_node, "offset", &ctx->offset))
 			return -EINVAL;
 	} else {
 		ctx->base = devm_platform_ioremap_resource(pdev, 0);
@@ -408,7 +407,7 @@ static int img_ascii_lcd_probe(struct platform_device *pdev)
 	if (err)
 		goto out_del_timer;
 
-	err = device_create_file(&pdev->dev, &dev_attr_message);
+	err = device_create_file(dev, &dev_attr_message);
 	if (err)
 		goto out_del_timer;
 
Signature · 1 line
2.25.1
author reviewer
#8 lore raw

PATCH v8 5/21 auxdisplay: img-ascii-lcd: Convert device attribute to sysfs_emit()

In reply to Geert Uytterhoeven

Convert the "message" device attribute from sprintf() to sysfs_emit(), as the latter is aware of the PAGE_SIZE buffer.

---
v8:
- No changes,

v7:
- No changes,

v6:
- No changes,

v5:
- No changes,

v4:
- No changes,

v3:
- No changes,

v2:
- No changes.

---
 drivers/auxdisplay/img-ascii-lcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/auxdisplay/img-ascii-lcd.c +1 -1
index 2b6e41ec57544faa..2b5640b638900a90 100644
@@ -326,7 +326,7 @@ static ssize_t message_show(struct device *dev, struct device_attribute *attr,
 {
 	struct img_ascii_lcd_ctx *ctx = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%s\n", ctx->message);
+	return sysfs_emit(buf, "%s\n", ctx->message);
 }
 
 /**
Signature · 1 line
2.25.1
author reviewer
#9 lore raw

PATCH v8 6/21 auxdisplay: Extract character line display core support

In reply to Geert Uytterhoeven

Extract the character line display core support from the simple ASCII LCD driver for the MIPS Boston, Malta & SEAD3 development boards into its own subdriver, so it can be reused for other displays.

As this moves the "message" device attribute in sysfs in a "linedisp.N" subdirectory, a symlink is added to preserve backwards compatibility.

---
Changes to img-ascii-lcd.c are untested due to lack of hardware. The backwards compatibility symlink has been tested by adding similar code to drivers/auxdisplay/ht16k33.c.

v8:
- No changes,

v7:
- No changes,

v6:
- No changes,

v5:
- No changes,

v4:
- No changes,

v3:
- Use compat_only_sysfs_link_entry_to_kobj() instead of cooking our own helper on top of kernfs_create_link(),

v2:
- Drop "select LINEDISP" from HT16K33 symbol,
- Add backwards compatibility symlink.

---
 drivers/auxdisplay/Kconfig         |   7 +
 drivers/auxdisplay/Makefile        |   1 +
 drivers/auxdisplay/img-ascii-lcd.c | 204 ++++---------------------
 drivers/auxdisplay/line-display.c  | 231 +++++++++++++++++++++++++++++
 drivers/auxdisplay/line-display.h  |  43 ++++++
 5 files changed, 312 insertions(+), 174 deletions(-)
 create mode 100644 drivers/auxdisplay/line-display.c
 create mode 100644 drivers/auxdisplay/line-display.h
drivers/auxdisplay/Kconfig +7 -0
index 1509cb74705a30ad..b41fdc5f7bf72a1b 100644
@@ -25,6 +25,12 @@ config CHARLCD
 	  This is some character LCD core interface that multiple drivers can
 	  use.
 
+config LINEDISP
+	tristate "Character line display core support" if COMPILE_TEST
+	help
+	  This is the core support for single-line character displays, to be
+	  selected by drivers that use it.
+
 config HD44780_COMMON
 	tristate "Common functions for HD44780 (and compatibles) LCD displays" if COMPILE_TEST
 	select CHARLCD
@@ -155,6 +161,7 @@ config IMG_ASCII_LCD
 	depends on HAS_IOMEM
 	default y if MIPS_MALTA
 	select MFD_SYSCON
+	select LINEDISP
 	help
 	  Enable this to support the simple ASCII LCD displays found on
 	  development boards such as the MIPS Boston, MIPS Malta & MIPS SEAD3
drivers/auxdisplay/Makefile +1 -0
index 307771027c893a5b..6968ed4d3f0a8930 100644
@@ -13,3 +13,4 @@ obj-$(CONFIG_HD44780)		+= hd44780.o
 obj-$(CONFIG_HT16K33)		+= ht16k33.o
 obj-$(CONFIG_PARPORT_PANEL)	+= panel.o
 obj-$(CONFIG_LCD2S)		+= lcd2s.o
+obj-$(CONFIG_LINEDISP)		+= line-display.o
drivers/auxdisplay/img-ascii-lcd.c +30 -174

289 lines not on this page · raw message

drivers/auxdisplay/line-display.c new file +231 -0

231 lines not on this page · raw message

drivers/auxdisplay/line-display.h new file +43 -0

43 lines not on this page · raw message

Signature · 1 line
2.25.1
author reviewer
#10 lore raw

PATCH v8 7/21 auxdisplay: linedisp: Use kmemdup_nul() helper

In reply to Geert Uytterhoeven

Use the existing kmemdup_nul() helper instead of open-coding the same operation.

---
v8:
- No changes,

v7:
- No changes,

v6:
- No changes,

v5:
- No changes,

v4:
- No changes,

v3:
- No changes,

v2:
- No changes.

---
 drivers/auxdisplay/line-display.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/auxdisplay/line-display.c +1 -4
index 4b97c20ac0b381ee..3f35199bc39f511f 100644
@@ -91,13 +91,10 @@ static int linedisp_display(struct linedisp *linedisp, const char *msg,
 		return 0;
 	}
 
-	new_msg = kmalloc(count + 1, GFP_KERNEL);
+	new_msg = kmemdup_nul(msg, count, GFP_KERNEL);
 	if (!new_msg)
 		return -ENOMEM;
 
-	memcpy(new_msg, msg, count);
-	new_msg[count] = 0;
-
 	kfree(linedisp->message);
 
 	linedisp->message = new_msg;
Signature · 1 line
2.25.1
author reviewer
#11 lore raw

PATCH v8 8/21 auxdisplay: linedisp: Add support for changing scroll rate

In reply to Geert Uytterhoeven

If the message to display is longer than the number of characters that the display can show, the message will be scrolled. Currently the scroll rate is fixed, moving every 500 ms.

Add support for changing the scroll rate through a "scroll_step_ms" device attribute in sysfs.

---
v8:
- No changes,

v7:
- No changes,

v6:
- No changes,

v5:
- No changes,

v4:
- No changes,

v3:
- No changes,

v2:
- No changes.

---
 drivers/auxdisplay/line-display.c | 37 +++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
drivers/auxdisplay/line-display.c +35 -2
index 3f35199bc39f511f..03e7f104aa1add32 100644
@@ -19,6 +19,8 @@
 
 #include "line-display.h"
 
+#define DEFAULT_SCROLL_RATE	(HZ / 2)
+
 /**
  * linedisp_scroll() - scroll the display by a character
  * @t: really a pointer to the private data structure
@@ -50,7 +52,7 @@ static void linedisp_scroll(struct timer_list *t)
 	linedisp->scroll_pos %= linedisp->message_len;
 
 	/* rearm the timer */
-	if (linedisp->message_len > num_chars)
+	if (linedisp->message_len > num_chars && linedisp->scroll_rate)
 		mod_timer(&linedisp->timer, jiffies + linedisp->scroll_rate);
 }
 
@@ -149,8 +151,39 @@ static ssize_t message_store(struct device *dev, struct device_attribute *attr,
 
 static DEVICE_ATTR_RW(message);
 
+static ssize_t scroll_step_ms_show(struct device *dev,
+				   struct device_attribute *attr, char *buf)
+{
+	struct linedisp *linedisp = container_of(dev, struct linedisp, dev);
+
+	return sysfs_emit(buf, "%u\n", jiffies_to_msecs(linedisp->scroll_rate));
+}
+
+static ssize_t scroll_step_ms_store(struct device *dev,
+				    struct device_attribute *attr,
+				    const char *buf, size_t count)
+{
+	struct linedisp *linedisp = container_of(dev, struct linedisp, dev);
+	unsigned int ms;
+
+	if (kstrtouint(buf, 10, &ms) != 0)
+		return -EINVAL;
+
+	linedisp->scroll_rate = msecs_to_jiffies(ms);
+	if (linedisp->message && linedisp->message_len > linedisp->num_chars) {
+		del_timer_sync(&linedisp->timer);
+		if (linedisp->scroll_rate)
+			linedisp_scroll(&linedisp->timer);
+	}
+
+	return count;
+}
+
+static DEVICE_ATTR_RW(scroll_step_ms);
+
 static struct attribute *linedisp_attrs[] = {
 	&dev_attr_message.attr,
+	&dev_attr_scroll_step_ms.attr,
 	NULL,
 };
 ATTRIBUTE_GROUPS(linedisp);
@@ -182,7 +215,7 @@ int linedisp_register(struct linedisp *linedisp, struct device *parent,
 	linedisp->update = update;
 	linedisp->buf = buf;
 	linedisp->num_chars = num_chars;
-	linedisp->scroll_rate = HZ / 2;
+	linedisp->scroll_rate = DEFAULT_SCROLL_RATE;
 
 	device_initialize(&linedisp->dev);
 	dev_set_name(&linedisp->dev, "linedisp.%lu",
Signature · 1 line
2.25.1
author reviewer
#12 lore raw

PATCH v8 9/21 auxdisplay: ht16k33: Connect backlight to fbdev

In reply to Geert Uytterhoeven

Currently /sys/class/graphics/fb0/bl_curve is not accessible (-ENODEV), as the driver does not connect the backlight to the frame buffer device. Fix this moving backlight initialization up, and filling in fb_info.bl_dev.

Fixes 8992da44c6805d53 ("auxdisplay: ht16k33: Driver for LED controller")

---
v8:
- No changes,

v7:
- Add Reviewed-by,

v6:
- No changes,

v5:
- No changes,

v4:
- No changes,

v3:
- No changes,

v2:
- New.

---
 drivers/auxdisplay/ht16k33.c | 56 ++++++++++++++++++------------------
 1 file changed, 28 insertions(+), 28 deletions(-)
drivers/auxdisplay/ht16k33.c +28 -28
index 1e69cc6d21a0dca2..2b630e194570f6e5 100644
@@ -413,6 +413,33 @@ static int ht16k33_probe(struct i2c_client *client,
 	if (err)
 		return err;
 
+	/* Backlight */
+	memset(&bl_props, 0, sizeof(struct backlight_properties));
+	bl_props.type = BACKLIGHT_RAW;
+	bl_props.max_brightness = MAX_BRIGHTNESS;
+
+	bl = devm_backlight_device_register(&client->dev, DRIVER_NAME"-bl",
+					    &client->dev, priv,
+					    &ht16k33_bl_ops, &bl_props);
+	if (IS_ERR(bl)) {
+		dev_err(&client->dev, "failed to register backlight\n");
+		return PTR_ERR(bl);
+	}
+
+	err = of_property_read_u32(node, "default-brightness-level",
+				   &dft_brightness);
+	if (err) {
+		dft_brightness = MAX_BRIGHTNESS;
+	} else if (dft_brightness > MAX_BRIGHTNESS) {
+		dev_warn(&client->dev,
+			 "invalid default brightness level: %u, using %u\n",
+			 dft_brightness, MAX_BRIGHTNESS);
+		dft_brightness = MAX_BRIGHTNESS;
+	}
+
+	bl->props.brightness = dft_brightness;
+	ht16k33_bl_update_status(bl);
+
 	/* Framebuffer (2 bytes per column) */
 	BUILD_BUG_ON(PAGE_SIZE < HT16K33_FB_SIZE);
 	fbdev->buffer = (unsigned char *) get_zeroed_page(GFP_KERNEL);
@@ -445,6 +472,7 @@ static int ht16k33_probe(struct i2c_client *client,
 	fbdev->info->screen_size = HT16K33_FB_SIZE;
 	fbdev->info->fix = ht16k33_fb_fix;
 	fbdev->info->var = ht16k33_fb_var;
+	fbdev->info->bl_dev = bl;
 	fbdev->info->pseudo_palette = NULL;
 	fbdev->info->flags = FBINFO_FLAG_DEFAULT;
 	fbdev->info->par = priv;
@@ -460,34 +488,6 @@ static int ht16k33_probe(struct i2c_client *client,
 			goto err_fbdev_unregister;
 	}
 
-	/* Backlight */
-	memset(&bl_props, 0, sizeof(struct backlight_properties));
-	bl_props.type = BACKLIGHT_RAW;
-	bl_props.max_brightness = MAX_BRIGHTNESS;
-
-	bl = devm_backlight_device_register(&client->dev, DRIVER_NAME"-bl",
-					    &client->dev, priv,
-					    &ht16k33_bl_ops, &bl_props);
-	if (IS_ERR(bl)) {
-		dev_err(&client->dev, "failed to register backlight\n");
-		err = PTR_ERR(bl);
-		goto err_fbdev_unregister;
-	}
-
-	err = of_property_read_u32(node, "default-brightness-level",
-				   &dft_brightness);
-	if (err) {
-		dft_brightness = MAX_BRIGHTNESS;
-	} else if (dft_brightness > MAX_BRIGHTNESS) {
-		dev_warn(&client->dev,
-			 "invalid default brightness level: %u, using %u\n",
-			 dft_brightness, MAX_BRIGHTNESS);
-		dft_brightness = MAX_BRIGHTNESS;
-	}
-
-	bl->props.brightness = dft_brightness;
-	ht16k33_bl_update_status(bl);
-
 	ht16k33_fb_queue(priv);
 	return 0;
 
Signature · 1 line
2.25.1
author reviewer
#13 lore raw

PATCH v8 10/21 auxdisplay: ht16k33: Fix frame buffer device blanking

In reply to Geert Uytterhoeven

As the ht16k33 frame buffer sub-driver does not register an fb_ops.fb_blank() handler, blanking does not work:

    $ echo 1 > /sys/class/graphics/fb0/blank
    sh: write error: Invalid argument

Fix this by providing a handler that always returns zero, to make sure blank events will be sent to the actual device handling the backlight.

Fixes 8992da44c6805d53 ("auxdisplay: ht16k33: Driver for LED controller")

---
v8:
- No changes,

v7:
- New.

---
 drivers/auxdisplay/ht16k33.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/auxdisplay/ht16k33.c +10 -0
index 2b630e194570f6e5..ed5808349990782c 100644
@@ -219,6 +219,15 @@ static const struct backlight_ops ht16k33_bl_ops = {
 	.check_fb	= ht16k33_bl_check_fb,
 };
 
+/*
+ * Blank events will be passed to the actual device handling the backlight when
+ * we return zero here.
+ */
+static int ht16k33_blank(int blank, struct fb_info *info)
+{
+	return 0;
+}
+
 static int ht16k33_mmap(struct fb_info *info, struct vm_area_struct *vma)
 {
 	struct ht16k33_priv *priv = info->par;
@@ -231,6 +240,7 @@ static const struct fb_ops ht16k33_fb_ops = {
 	.owner = THIS_MODULE,
 	.fb_read = fb_sys_read,
 	.fb_write = fb_sys_write,
+	.fb_blank = ht16k33_blank,
 	.fb_fillrect = sys_fillrect,
 	.fb_copyarea = sys_copyarea,
 	.fb_imageblit = sys_imageblit,
Signature · 1 line
2.25.1
author reviewer
#14 lore raw

PATCH v8 11/21 auxdisplay: ht16k33: Use HT16K33_FB_SIZE in ht16k33_initialize()

In reply to Geert Uytterhoeven

Use the existing HT16K33_FB_SIZE definition instead of open-coding the same calculation using an hardcoded value.
While at it, restore reverse Christmas tree variable declaration order.

---
v8:
- No changes,

v7:
- No changes,

v6:
- No changes,

v5:
- No changes,

v4:
- No changes,

v3:
- No changes,

v2:
- Add Acked-by.

---
 drivers/auxdisplay/ht16k33.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/auxdisplay/ht16k33.c +1 -1
index ed5808349990782c..fed2f8bd2d27c65b 100644
@@ -168,9 +168,9 @@ static void ht16k33_fb_update(struct work_struct *work)
 
 static int ht16k33_initialize(struct ht16k33_priv *priv)
 {
+	uint8_t data[HT16K33_FB_SIZE];
 	uint8_t byte;
 	int err;
-	uint8_t data[HT16K33_MATRIX_LED_MAX_COLS * 2];
 
 	/* Clear RAM (8 * 16 bits) */
 	memset(data, 0, sizeof(data));
Signature · 1 line
2.25.1
author reviewer
#15 lore raw

PATCH v8 12/21 auxdisplay: ht16k33: Remove unneeded error check in keypad probe()

In reply to Geert Uytterhoeven

There is no need to check the return code of input_register_device(), just propagate it to the caller.

---
v8:
- No changes,

v7:
- No changes,

v6:
- No changes,

v5:
- No changes,

v4:
- No changes,

v3:
- No changes,

v2:
- Add Acked-by.

---
 drivers/auxdisplay/ht16k33.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/auxdisplay/ht16k33.c +1 -5
index fed2f8bd2d27c65b..1ce73c4172c89244 100644
@@ -388,11 +388,7 @@ static int ht16k33_keypad_probe(struct i2c_client *client,
 
 	ht16k33_keypad_stop(keypad->dev);
 
-	err = input_register_device(keypad->dev);
-	if (err)
-		return err;
-
-	return 0;
+	return input_register_device(keypad->dev);
 }
 
 static int ht16k33_probe(struct i2c_client *client,
Signature · 1 line
2.25.1
author reviewer
#16 lore raw

PATCH v8 13/21 auxdisplay: ht16k33: Convert to simple i2c probe function

In reply to Geert Uytterhoeven

ht16k33_probe() does not use the passed i2c_device_id, so the driver can be converted trivially to the new-style of i2c probing.

---
v8:
- No changes,

v7:
- No changes,

v6:
- No changes,

v5:
- No changes,

v4:
- No changes,

v3:
- No changes,

v2:
- Add Acked-by.

---
 drivers/auxdisplay/ht16k33.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/auxdisplay/ht16k33.c +2 -3
index 1ce73c4172c89244..d0d7b55059aa181e 100644
@@ -391,8 +391,7 @@ static int ht16k33_keypad_probe(struct i2c_client *client,
 	return input_register_device(keypad->dev);
 }
 
-static int ht16k33_probe(struct i2c_client *client,
-				  const struct i2c_device_id *id)
+static int ht16k33_probe(struct i2c_client *client)
 {
 	int err;
 	uint32_t dft_brightness;
@@ -533,7 +532,7 @@ static const struct of_device_id ht16k33_of_match[] = {
 MODULE_DEVICE_TABLE(of, ht16k33_of_match);
 
 static struct i2c_driver ht16k33_driver = {
-	.probe		= ht16k33_probe,
+	.probe_new	= ht16k33_probe,
 	.remove		= ht16k33_remove,
 	.driver		= {
 		.name		= DRIVER_NAME,
Signature · 1 line
2.25.1
author reviewer
#17 lore raw

PATCH v8 14/21 auxdisplay: ht16k33: Add helper variable dev

In reply to Geert Uytterhoeven

This driver has many users of "client->dev". Add shorthands to simplify the code.

---
v8:
- No changes,

v7:
- No changes,

v6:
- No changes,

v5:
- No changes,

v4:
- No changes,

v3:
- No changes,

v2:
- Add Acked-by,
- Rebased.

---
 drivers/auxdisplay/ht16k33.c | 43 ++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 21 deletions(-)
drivers/auxdisplay/ht16k33.c +22 -21
index d0d7b55059aa181e..dcf530a9390b6f9c 100644
@@ -326,7 +326,8 @@ static void ht16k33_keypad_stop(struct input_dev *dev)
 static int ht16k33_keypad_probe(struct i2c_client *client,
 				struct ht16k33_keypad *keypad)
 {
-	struct device_node *node = client->dev.of_node;
+	struct device *dev = &client->dev;
+	struct device_node *node = dev->of_node;
 	u32 rows = HT16K33_MATRIX_KEYPAD_MAX_ROWS;
 	u32 cols = HT16K33_MATRIX_KEYPAD_MAX_COLS;
 	int err;
@@ -334,7 +335,7 @@ static int ht16k33_keypad_probe(struct i2c_client *client,
 	keypad->client = client;
 	init_waitqueue_head(&keypad->wait);
 
-	keypad->dev = devm_input_allocate_device(&client->dev);
+	keypad->dev = devm_input_allocate_device(dev);
 	if (!keypad->dev)
 		return -ENOMEM;
 
@@ -351,17 +352,17 @@ static int ht16k33_keypad_probe(struct i2c_client *client,
 	err = of_property_read_u32(node, "debounce-delay-ms",
 				   &keypad->debounce_ms);
 	if (err) {
-		dev_err(&client->dev, "key debounce delay not specified\n");
+		dev_err(dev, "key debounce delay not specified\n");
 		return err;
 	}
 
-	err = matrix_keypad_parse_of_params(&client->dev, &rows, &cols);
+	err = matrix_keypad_parse_of_params(dev, &rows, &cols);
 	if (err)
 		return err;
 	if (rows > HT16K33_MATRIX_KEYPAD_MAX_ROWS ||
 	    cols > HT16K33_MATRIX_KEYPAD_MAX_COLS) {
-		dev_err(&client->dev, "%u rows or %u cols out of range in DT\n",
-			rows, cols);
+		dev_err(dev, "%u rows or %u cols out of range in DT\n", rows,
+			cols);
 		return -ERANGE;
 	}
 
@@ -372,17 +373,17 @@ static int ht16k33_keypad_probe(struct i2c_client *client,
 	err = matrix_keypad_build_keymap(NULL, NULL, rows, cols, NULL,
 					 keypad->dev);
 	if (err) {
-		dev_err(&client->dev, "failed to build keymap\n");
+		dev_err(dev, "failed to build keymap\n");
 		return err;
 	}
 
-	err = devm_request_threaded_irq(&client->dev, client->irq,
-					NULL, ht16k33_keypad_irq_thread,
+	err = devm_request_threaded_irq(dev, client->irq, NULL,
+					ht16k33_keypad_irq_thread,
 					IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
 					DRIVER_NAME, keypad);
 	if (err) {
-		dev_err(&client->dev, "irq request failed %d, error %d\n",
-			client->irq, err);
+		dev_err(dev, "irq request failed %d, error %d\n", client->irq,
+			err);
 		return err;
 	}
 
@@ -399,14 +400,15 @@ static int ht16k33_probe(struct i2c_client *client)
 	struct backlight_properties bl_props;
 	struct ht16k33_priv *priv;
 	struct ht16k33_fbdev *fbdev;
-	struct device_node *node = client->dev.of_node;
+	struct device *dev = &client->dev;
+	struct device_node *node = dev->of_node;
 
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
-		dev_err(&client->dev, "i2c_check_functionality error\n");
+		dev_err(dev, "i2c_check_functionality error\n");
 		return -EIO;
 	}
 
-	priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
 
@@ -423,11 +425,10 @@ static int ht16k33_probe(struct i2c_client *client)
 	bl_props.type = BACKLIGHT_RAW;
 	bl_props.max_brightness = MAX_BRIGHTNESS;
 
-	bl = devm_backlight_device_register(&client->dev, DRIVER_NAME"-bl",
-					    &client->dev, priv,
+	bl = devm_backlight_device_register(dev, DRIVER_NAME"-bl", dev, priv,
 					    &ht16k33_bl_ops, &bl_props);
 	if (IS_ERR(bl)) {
-		dev_err(&client->dev, "failed to register backlight\n");
+		dev_err(dev, "failed to register backlight\n");
 		return PTR_ERR(bl);
 	}
 
@@ -436,7 +437,7 @@ static int ht16k33_probe(struct i2c_client *client)
 	if (err) {
 		dft_brightness = MAX_BRIGHTNESS;
 	} else if (dft_brightness > MAX_BRIGHTNESS) {
-		dev_warn(&client->dev,
+		dev_warn(dev,
 			 "invalid default brightness level: %u, using %u\n",
 			 dft_brightness, MAX_BRIGHTNESS);
 		dft_brightness = MAX_BRIGHTNESS;
@@ -451,13 +452,13 @@ static int ht16k33_probe(struct i2c_client *client)
 	if (!fbdev->buffer)
 		return -ENOMEM;
 
-	fbdev->cache = devm_kmalloc(&client->dev, HT16K33_FB_SIZE, GFP_KERNEL);
+	fbdev->cache = devm_kmalloc(dev, HT16K33_FB_SIZE, GFP_KERNEL);
 	if (!fbdev->cache) {
 		err = -ENOMEM;
 		goto err_fbdev_buffer;
 	}
 
-	fbdev->info = framebuffer_alloc(0, &client->dev);
+	fbdev->info = framebuffer_alloc(0, dev);
 	if (!fbdev->info) {
 		err = -ENOMEM;
 		goto err_fbdev_buffer;
@@ -466,7 +467,7 @@ static int ht16k33_probe(struct i2c_client *client)
 	err = of_property_read_u32(node, "refresh-rate-hz",
 		&fbdev->refresh_rate);
 	if (err) {
-		dev_err(&client->dev, "refresh rate not specified\n");
+		dev_err(dev, "refresh rate not specified\n");
 		goto err_fbdev_info;
 	}
 	fb_bl_default_curve(fbdev->info, 0, MIN_BRIGHTNESS, MAX_BRIGHTNESS);
Signature · 1 line
2.25.1
author reviewer
#18 lore raw

PATCH v8 15/21 auxdisplay: ht16k33: Move delayed work

In reply to Geert Uytterhoeven

Move delayed_work from ht16k33_fbdev to ht16k33_priv, as it is not specific to dot-matrix displays, but common to all display types.

---
v8:
- No changes,

v7:
- Add Acked-by,

v6:
- No changes,

v5:
- No changes,

v4:
- No changes,

v3:
- No changes,

v2:
- No changes.

---
 drivers/auxdisplay/ht16k33.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/auxdisplay/ht16k33.c +7 -8
index dcf530a9390b6f9c..b50cbf7e57ba26d7 100644
@@ -65,11 +65,11 @@ struct ht16k33_fbdev {
 	uint32_t refresh_rate;
 	uint8_t *buffer;
 	uint8_t *cache;
-	struct delayed_work work;
 };
 
 struct ht16k33_priv {
 	struct i2c_client *client;
+	struct delayed_work work;
 	struct ht16k33_keypad keypad;
 	struct ht16k33_fbdev fbdev;
 };
@@ -117,7 +117,7 @@ static void ht16k33_fb_queue(struct ht16k33_priv *priv)
 {
 	struct ht16k33_fbdev *fbdev = &priv->fbdev;
 
-	schedule_delayed_work(&fbdev->work, HZ / fbdev->refresh_rate);
+	schedule_delayed_work(&priv->work, HZ / fbdev->refresh_rate);
 }
 
 /*
@@ -125,10 +125,9 @@ static void ht16k33_fb_queue(struct ht16k33_priv *priv)
  */
 static void ht16k33_fb_update(struct work_struct *work)
 {
-	struct ht16k33_fbdev *fbdev =
-		container_of(work, struct ht16k33_fbdev, work.work);
-	struct ht16k33_priv *priv =
-		container_of(fbdev, struct ht16k33_priv, fbdev);
+	struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv,
+						 work.work);
+	struct ht16k33_fbdev *fbdev = &priv->fbdev;
 
 	uint8_t *p1, *p2;
 	int len, pos = 0, first = -1;
@@ -472,7 +471,7 @@ static int ht16k33_probe(struct i2c_client *client)
 	}
 	fb_bl_default_curve(fbdev->info, 0, MIN_BRIGHTNESS, MAX_BRIGHTNESS);
 
-	INIT_DELAYED_WORK(&fbdev->work, ht16k33_fb_update);
+	INIT_DELAYED_WORK(&priv->work, ht16k33_fb_update);
 	fbdev->info->fbops = &ht16k33_fb_ops;
 	fbdev->info->screen_base = (char __iomem *) fbdev->buffer;
 	fbdev->info->screen_size = HT16K33_FB_SIZE;
@@ -512,7 +511,7 @@ static int ht16k33_remove(struct i2c_client *client)
 	struct ht16k33_priv *priv = i2c_get_clientdata(client);
 	struct ht16k33_fbdev *fbdev = &priv->fbdev;
 
-	cancel_delayed_work_sync(&fbdev->work);
+	cancel_delayed_work_sync(&priv->work);
 	unregister_framebuffer(fbdev->info);
 	framebuffer_release(fbdev->info);
 	free_page((unsigned long) fbdev->buffer);
Signature · 1 line
2.25.1
author reviewer
#19 lore raw

PATCH v8 16/21 auxdisplay: ht16k33: Extract ht16k33_brightness_set()

In reply to Geert Uytterhoeven

Extract brightness handling into a helper function, so it can be called from multiple places.

---
v8:
- No changes,

v7:
- Add Reviewed-by,

v6:
- No changes,

v5:
- No changes,

v4:
- No changes,

v3:
- Use "err" instead of "error" to be consistent with existing driver naming style,

v2:
- No changes.

---
 drivers/auxdisplay/ht16k33.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/auxdisplay/ht16k33.c +19 -6
index b50cbf7e57ba26d7..60e616c0e932cd84 100644
@@ -113,6 +113,22 @@ static int ht16k33_display_off(struct ht16k33_priv *priv)
 	return i2c_smbus_write_byte(priv->client, REG_DISPLAY_SETUP);
 }
 
+static int ht16k33_brightness_set(struct ht16k33_priv *priv,
+				  unsigned int brightness)
+{
+	int err;
+
+	if (brightness == 0)
+		return ht16k33_display_off(priv);
+
+	err = ht16k33_display_on(priv);
+	if (err)
+		return err;
+
+	return i2c_smbus_write_byte(priv->client,
+				    REG_BRIGHTNESS | (brightness - 1));
+}
+
 static void ht16k33_fb_queue(struct ht16k33_priv *priv)
 {
 	struct ht16k33_fbdev *fbdev = &priv->fbdev;
@@ -197,13 +213,10 @@ static int ht16k33_bl_update_status(struct backlight_device *bl)
 
 	if (bl->props.power != FB_BLANK_UNBLANK ||
 	    bl->props.fb_blank != FB_BLANK_UNBLANK ||
-	    bl->props.state & BL_CORE_FBBLANK || brightness == 0) {
-		return ht16k33_display_off(priv);
-	}
+	    bl->props.state & BL_CORE_FBBLANK)
+		brightness = 0;
 
-	ht16k33_display_on(priv);
-	return i2c_smbus_write_byte(priv->client,
-				    REG_BRIGHTNESS | (brightness - 1));
+	return ht16k33_brightness_set(priv, brightness);
 }
 
 static int ht16k33_bl_check_fb(struct backlight_device *bl, struct fb_info *fi)
Signature · 1 line
2.25.1
author reviewer
#20 lore raw

PATCH v8 17/21 auxdisplay: ht16k33: Extract frame buffer probing

In reply to Geert Uytterhoeven

Extract all frame buffer (including backlight) probing into ht16k33_fbdev_probe().

Call ht16k33_fbdev_probe() after ht16k33_keypad_probe(), as the latter does not need any manual cleanup in the probe error path.

---
v8:
- No changes,

v7:
- Add Reviewed-by,

v6:
- No changes,

v5:
- No changes,

v4:
- No changes,

v3:
- Pass "dev" instead of "client" to ht16k33_fbdev_probe(),
- Drop local variable "node",

v2:
- Rebased.

---
 drivers/auxdisplay/ht16k33.c | 101 ++++++++++++++++++-----------------
 1 file changed, 53 insertions(+), 48 deletions(-)
drivers/auxdisplay/ht16k33.c +53 -48
index 60e616c0e932cd84..8993d27909109a98 100644
@@ -404,33 +404,13 @@ static int ht16k33_keypad_probe(struct i2c_client *client,
 	return input_register_device(keypad->dev);
 }
 
-static int ht16k33_probe(struct i2c_client *client)
+static int ht16k33_fbdev_probe(struct device *dev, struct ht16k33_priv *priv,
+			       uint32_t brightness)
 {
-	int err;
-	uint32_t dft_brightness;
-	struct backlight_device *bl;
+	struct ht16k33_fbdev *fbdev = &priv->fbdev;
 	struct backlight_properties bl_props;
-	struct ht16k33_priv *priv;
-	struct ht16k33_fbdev *fbdev;
-	struct device *dev = &client->dev;
-	struct device_node *node = dev->of_node;
-
-	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
-		dev_err(dev, "i2c_check_functionality error\n");
-		return -EIO;
-	}
-
-	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv)
-		return -ENOMEM;
-
-	priv->client = client;
-	i2c_set_clientdata(client, priv);
-	fbdev = &priv->fbdev;
-
-	err = ht16k33_initialize(priv);
-	if (err)
-		return err;
+	struct backlight_device *bl;
+	int err;
 
 	/* Backlight */
 	memset(&bl_props, 0, sizeof(struct backlight_properties));
@@ -444,18 +424,7 @@ static int ht16k33_probe(struct i2c_client *client)
 		return PTR_ERR(bl);
 	}
 
-	err = of_property_read_u32(node, "default-brightness-level",
-				   &dft_brightness);
-	if (err) {
-		dft_brightness = MAX_BRIGHTNESS;
-	} else if (dft_brightness > MAX_BRIGHTNESS) {
-		dev_warn(dev,
-			 "invalid default brightness level: %u, using %u\n",
-			 dft_brightness, MAX_BRIGHTNESS);
-		dft_brightness = MAX_BRIGHTNESS;
-	}
-
-	bl->props.brightness = dft_brightness;
+	bl->props.brightness = brightness;
 	ht16k33_bl_update_status(bl);
 
 	/* Framebuffer (2 bytes per column) */
@@ -476,8 +445,8 @@ static int ht16k33_probe(struct i2c_client *client)
 		goto err_fbdev_buffer;
 	}
 
-	err = of_property_read_u32(node, "refresh-rate-hz",
-		&fbdev->refresh_rate);
+	err = of_property_read_u32(dev->of_node, "refresh-rate-hz",
+				   &fbdev->refresh_rate);
 	if (err) {
 		dev_err(dev, "refresh rate not specified\n");
 		goto err_fbdev_info;
@@ -499,18 +468,9 @@ static int ht16k33_probe(struct i2c_client *client)
 	if (err)
 		goto err_fbdev_info;
 
-	/* Keypad */
-	if (client->irq > 0) {
-		err = ht16k33_keypad_probe(client, &priv->keypad);
-		if (err)
-			goto err_fbdev_unregister;
-	}
-
 	ht16k33_fb_queue(priv);
 	return 0;
 
-err_fbdev_unregister:
-	unregister_framebuffer(fbdev->info);
 err_fbdev_info:
 	framebuffer_release(fbdev->info);
 err_fbdev_buffer:
@@ -519,6 +479,51 @@ static int ht16k33_probe(struct i2c_client *client)
 	return err;
 }
 
+static int ht16k33_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct ht16k33_priv *priv;
+	uint32_t dft_brightness;
+	int err;
+
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
+		dev_err(dev, "i2c_check_functionality error\n");
+		return -EIO;
+	}
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->client = client;
+	i2c_set_clientdata(client, priv);
+
+	err = ht16k33_initialize(priv);
+	if (err)
+		return err;
+
+	err = of_property_read_u32(dev->of_node, "default-brightness-level",
+				   &dft_brightness);
+	if (err) {
+		dft_brightness = MAX_BRIGHTNESS;
+	} else if (dft_brightness > MAX_BRIGHTNESS) {
+		dev_warn(dev,
+			 "invalid default brightness level: %u, using %u\n",
+			 dft_brightness, MAX_BRIGHTNESS);
+		dft_brightness = MAX_BRIGHTNESS;
+	}
+
+	/* Keypad */
+	if (client->irq > 0) {
+		err = ht16k33_keypad_probe(client, &priv->keypad);
+		if (err)
+			return err;
+	}
+
+	/* Frame Buffer Display */
+	return ht16k33_fbdev_probe(dev, priv, dft_brightness);
+}
+
 static int ht16k33_remove(struct i2c_client *client)
 {
 	struct ht16k33_priv *priv = i2c_get_clientdata(client);
Signature · 1 line
2.25.1
author reviewer
#21 lore raw

PATCH v8 18/21 auxdisplay: ht16k33: Add support for segment displays

In reply to Geert Uytterhoeven

The Holtek HT16K33 LED controller is not only used for driving dot-matrix displays, but also for driving segment displays.

Add support for 4-digit 7-segment and quad 14-segment alphanumeric displays, like the Adafruit 7-segment and 14-segment display backpack and FeatherWing expansion boards. Use the character line display core support to display a message, which will be scrolled if it doesn't fit.

---
The 7-segment support is based on schematics, and untested on actual hardware.

v8:
- No changes,

v7:
- Add Acked-by,
- Set correct brightness in ht16k33_seg_probe(),

v6:
- No changes,

v5:
- No changes,

v4:
- No changes,

v3:
- Pass "dev" instead of "client" to ht16k33_seg_probe(),
- Remove unneeded inclusion of <linux/leds.h> and <linux/of_device.h>,

v2:
- Move "select LINEDISP" to this patch,
- Set "err = -EINVAL" in switch() case that cannot happen.

---
 drivers/auxdisplay/Kconfig   |   1 +
 drivers/auxdisplay/ht16k33.c | 196 +++++++++++++++++++++++++++++++++--
 2 files changed, 190 insertions(+), 7 deletions(-)
drivers/auxdisplay/Kconfig +1 -0
index b41fdc5f7bf72a1b..42fc7b155de09dbc 100644
@@ -176,6 +176,7 @@ config HT16K33
 	select FB_SYS_IMAGEBLIT
 	select INPUT_MATRIXKMAP
 	select FB_BACKLIGHT
+	select LINEDISP
 	help
 	  Say yes here to add support for Holtek HT16K33, RAM mapping 16*8
 	  LED controller driver with keyscan.
drivers/auxdisplay/ht16k33.c +189 -7

269 lines not on this page · raw message

Signature · 1 line
2.25.1
author reviewer
#22 lore raw

PATCH v8 19/21 dt-bindings: auxdisplay: ht16k33: Document LED subnode

In reply to Geert Uytterhoeven

Extend the Holtek HT16K33 LED controller Device Tree bindings with an LED subnode, conforming to the standard LED bindings.

This allows the user to exert more control, like specifying LED color, function, and/or trigger, to extend LED functionality beyond a simple display backlight.

---
v8:
- No changes,

v7:
- Add linux,default-trigger to example,

v6:
- No changes,

v5:
- No changes,

v4:
- Add Reviewed-by,

v3:
- New.

---
 .../bindings/auxdisplay/holtek,ht16k33.yaml          | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/auxdisplay/holtek,ht16k33.yaml +12 -0
index 6baf1200c9d8488e..fc4873deb76f3190 100644
@@ -48,6 +48,11 @@ properties:
     default: 16
     description: Initial brightness level
 
+  led:
+    type: object
+    $ref: /schemas/leds/common.yaml#
+    unevaluatedProperties: false
+
 required:
   - compatible
   - reg
@@ -66,6 +71,7 @@ examples:
   - |
     #include <dt-bindings/interrupt-controller/irq.h>
     #include <dt-bindings/input/input.h>
+    #include <dt-bindings/leds/common.h>
     i2c1 {
             #address-cells = <1>;
             #size-cells = <0>;
@@ -87,5 +93,11 @@ examples:
                                    <MATRIX_KEY(4, 1, KEY_F9)>,
                                    <MATRIX_KEY(5, 1, KEY_F3)>,
                                    <MATRIX_KEY(6, 1, KEY_F1)>;
+
+                    led {
+                            color = <LED_COLOR_ID_RED>;
+                            function = LED_FUNCTION_BACKLIGHT;
+                            linux,default-trigger = "backlight";
+                    };
             };
       };
Signature · 1 line
2.25.1
author reviewer
#23 lore raw

PATCH v8 20/21 auxdisplay: ht16k33: Add LED support

In reply to Geert Uytterhoeven

Instantiate a single LED based on the "led" subnode in DT. This allows the user to control display brightness and blinking (backed by hardware support) through the LED class API and triggers, and exposes the display color. The LED will be named "auxdisplay:<color>:<function>".

When running in dot-matrix mode and if no "led" subnode is found, the driver falls back to the traditional backlight mode, to preserve backwards compatibility.

---
v8:
- Add Reviewed-by,

v7:
- Add missing call to ht16k33_brightness_set() in ht16k33_fbdev_probe(), to make sure brightness and blinking are set to a sane state,

v6:
- Add Reviewed-by,
- Reorder operations in ht16k33_led_probe() to simplify future conversion to device properties,

v5:
- Add missing select NEW_LEDS,

v4:
- Add missing select LEDS_CLASS,

v3:
- Remove unneeded C++ comment,
- Use "err" instead of "error" to be consistent with existing driver naming style,
- Make the creation of the LED device dependent on the presence of the "led" subnode in DT, so it can be used in dot-matrix mode too.
- Use led_init_data() and devm_led_classdev_register_ext() to retrieve all LED properties from DT, instead of manual LED name construction based on just the "color" property,

v2:
- Use "auxdisplay" instead of DRIVER_NAME in LED name.

---
 drivers/auxdisplay/Kconfig   |   2 +
 drivers/auxdisplay/ht16k33.c | 126 ++++++++++++++++++++++++++++++-----
 2 files changed, 112 insertions(+), 16 deletions(-)
drivers/auxdisplay/Kconfig +2 -0
index 42fc7b155de09dbc..e32ef7f9945d49b2 100644
@@ -176,6 +176,8 @@ config HT16K33
 	select FB_SYS_IMAGEBLIT
 	select INPUT_MATRIXKMAP
 	select FB_BACKLIGHT
+	select NEW_LEDS
+	select LEDS_CLASS
 	select LINEDISP
 	help
 	  Say yes here to add support for Holtek HT16K33, RAM mapping 16*8
drivers/auxdisplay/ht16k33.c +110 -16

192 lines not on this page · raw message

Signature · 1 line
2.25.1
author reviewer
#24 lore raw

PATCH v8 21/21 auxdisplay: ht16k33: Make use of device properties

In reply to Geert Uytterhoeven

The device property API allows drivers to gather device resources from different sources, such as ACPI, and lift the dependency on Device Tree. Convert the driver to unleash the power of the device property API.

---
v8:
- Add Acked-by,

v7:
- Integrate into this series,
- Add Reviewed-by,
- Use device_property_read_bool() as replacement for

    of_get_property(),
  - Call matrix_keypad_parse_properties() instead of
    matrix_keypad_parse_of_params().
---
 drivers/auxdisplay/Kconfig   |  2 +-
 drivers/auxdisplay/ht16k33.c | 27 ++++++++++++---------------
 2 files changed, 13 insertions(+), 16 deletions(-)
drivers/auxdisplay/Kconfig +1 -1
index e32ef7f9945d49b2..64012cda4d126707 100644
@@ -169,7 +169,7 @@ config IMG_ASCII_LCD
 
 config HT16K33
 	tristate "Holtek Ht16K33 LED controller with keyscan"
-	depends on FB && OF && I2C && INPUT
+	depends on FB && I2C && INPUT
 	select FB_SYS_FOPS
 	select FB_SYS_FILLRECT
 	select FB_SYS_COPYAREA
drivers/auxdisplay/ht16k33.c +12 -15
index aef3dc87dc9f5ed2..1134ae9f30de4baa 100644
@@ -12,7 +12,7 @@
 #include <linux/module.h>
 #include <linux/interrupt.h>
 #include <linux/i2c.h>
-#include <linux/of.h>
+#include <linux/property.h>
 #include <linux/fb.h>
 #include <linux/slab.h>
 #include <linux/backlight.h>
@@ -491,15 +491,13 @@ static int ht16k33_led_probe(struct device *dev, struct led_classdev *led,
 			     unsigned int brightness)
 {
 	struct led_init_data init_data = {};
-	struct device_node *node;
 	int err;
 
 	/* The LED is optional */
-	node = of_get_child_by_name(dev->of_node, "led");
-	if (!node)
+	init_data.fwnode = device_get_named_child_node(dev, "led");
+	if (!init_data.fwnode)
 		return 0;
 
-	init_data.fwnode = of_fwnode_handle(node);
 	init_data.devicename = "auxdisplay";
 	init_data.devname_mandatory = true;
 
@@ -520,7 +518,6 @@ static int ht16k33_keypad_probe(struct i2c_client *client,
 				struct ht16k33_keypad *keypad)
 {
 	struct device *dev = &client->dev;
-	struct device_node *node = dev->of_node;
 	u32 rows = HT16K33_MATRIX_KEYPAD_MAX_ROWS;
 	u32 cols = HT16K33_MATRIX_KEYPAD_MAX_COLS;
 	int err;
@@ -539,17 +536,17 @@ static int ht16k33_keypad_probe(struct i2c_client *client,
 	keypad->dev->open = ht16k33_keypad_start;
 	keypad->dev->close = ht16k33_keypad_stop;
 
-	if (!of_get_property(node, "linux,no-autorepeat", NULL))
+	if (!device_property_read_bool(dev, "linux,no-autorepeat"))
 		__set_bit(EV_REP, keypad->dev->evbit);
 
-	err = of_property_read_u32(node, "debounce-delay-ms",
-				   &keypad->debounce_ms);
+	err = device_property_read_u32(dev, "debounce-delay-ms",
+				       &keypad->debounce_ms);
 	if (err) {
 		dev_err(dev, "key debounce delay not specified\n");
 		return err;
 	}
 
-	err = matrix_keypad_parse_of_params(dev, &rows, &cols);
+	err = matrix_keypad_parse_properties(dev, &rows, &cols);
 	if (err)
 		return err;
 	if (rows > HT16K33_MATRIX_KEYPAD_MAX_ROWS ||
@@ -634,8 +631,8 @@ static int ht16k33_fbdev_probe(struct device *dev, struct ht16k33_priv *priv,
 		goto err_fbdev_buffer;
 	}
 
-	err = of_property_read_u32(dev->of_node, "refresh-rate-hz",
-				   &fbdev->refresh_rate);
+	err = device_property_read_u32(dev, "refresh-rate-hz",
+				       &fbdev->refresh_rate);
 	if (err) {
 		dev_err(dev, "refresh rate not specified\n");
 		goto err_fbdev_info;
@@ -741,8 +738,8 @@ static int ht16k33_probe(struct i2c_client *client)
 	if (err)
 		return err;
 
-	err = of_property_read_u32(dev->of_node, "default-brightness-level",
-				   &dft_brightness);
+	err = device_property_read_u32(dev, "default-brightness-level",
+				       &dft_brightness);
 	if (err) {
 		dft_brightness = MAX_BRIGHTNESS;
 	} else if (dft_brightness > MAX_BRIGHTNESS) {
@@ -830,7 +827,7 @@ static struct i2c_driver ht16k33_driver = {
 	.remove		= ht16k33_remove,
 	.driver		= {
 		.name		= DRIVER_NAME,
-		.of_match_table	= of_match_ptr(ht16k33_of_match),
+		.of_match_table	= ht16k33_of_match,
 	},
 	.id_table = ht16k33_i2c_match,
 };
Signature · 1 line
2.25.1
#25 lore raw
In reply to Geert Uytterhoeven

Hi Geert,

Quoted 9 lines · Geert Uytterhoeven

The Holtek HT16K33 LED controller is not only used for driving dot-matrix displays, but also for driving segment displays. The current auxdisplay driver is limited to dot-matrix displays, which are exposed as a frame buffer device.

This patch series extends the driver to 4-digit 7-segment and quad 14-segment alphanumeric displays, allowing the user to display and scroll text messages.

Thanks for all your work on this. Unless somebody is against this, I will pick it up.

Cheers,
Miguel

Applied
#26 lore raw
Quoted 3 lines · Miguel Ojeda

Thanks for all your work on this. Unless somebody is against this, I will pick it up.

Applied, thanks!

Cheers,
Miguel