auxdisplay: Add TM16xx 7-segment LED matrix display controllers driver
Subsystems (3)
v5 cover auxdisplay: Add TM16xx 7-segment LED matrix display controllers driver
This series adds mainline kernel support for TM16xx family LED matrix controllers and compatible chips, widely used in auxiliary displays on TV boxes and embedded devices.
Many consumer devices, particularly TV boxes, use auxiliary displays based on TM16xx controllers to show status information such as time, network connectivity and system state. Currently, there is no mainline kernel support for these displays, forcing users to rely on out-of-tree drivers or userspace solutions that access hardware interfaces directly.
This driver provides unified TM16xx support through the LED subsystem with both I2C and SPI communication protocols. It integrates with the LED class framework, enabling control via standard sysfs interfaces and LED triggers, while supporting keypad input when hardware connections are available.
The driver supports multiple controller families from various vendors:
- Titan Micro Electronics: TM1618, TM1620, TM1628, TM1638, TM1650
- Fuda Hisi Microelectronics: FD620, FD628, FD650, FD655, FD6551
- i-Core Electronics: AiP650, AiP1618, AiP1628
- Princeton Technology: PT6964
- Winrise Technology: HBS658
Key features:
- 7-segment display support with flexible digit/segment mapping
- Individual LED icon control through LED class devices
- Optional keypad scanning with configurable key mapping
- Device tree configuration for board-specific wiring layouts
- LED trigger integration for automatic system event indication
- I2C and SPI protocol support depending on controller interface
Device tree bindings describe board-specific display wiring since controllers are layout-agnostic. The bindings use separate 'digits' and 'leds' containers with specific addressing schemes to accommodate the hardware's grid/segment matrix organization.
Tested on multiple ARM TV boxes (H96 Max, Magicsee N5, Tanix TX3 Mini, Tanix TX6, X92, X96 Max) across different SoC platforms (Rockchip, Amlogic, Allwinner) in both I2C and SPI configurations.
User space utilities available at:
https://github.com/jefflessard/tm16xx-display
Dependencies:
- linedisp_attach()/_detach() infrastructure introduced in patch series:
"auxdisplay: linedisp: support attribute attachment to auxdisplay devices"
- fwnode_for_each_available_child_node_scoped() from patch series:
"device property: Add scoped fwnode child node iterators"
Note: This driver is placed in drivers/auxdisplay rather than drivers/leds based on previous maintainer guidance. LED maintainer Pavel Machek recommended auxdisplay for TM1628-based display drivers:
https://lore.kernel.org/linux-devicetree/[email protected]/
Regmap Evaluation:
TM16xx controllers use command-based 2-wire/3-wire protocols that share sufficient commonalities with I2C/SPI to leverage their subsystems, but are not fully compliant with standard register-based access patterns:
- TM1650 example: 0x48 is a control command while 0x4F is a keyscan command. These appear as adjacent I2C "addresses" but are distinct commands with different data directions and payloads, not read/write pairs of the same register.
- TM1628 example: Initialization requires coordinated sequences followed by indexed data writes. Single regmap read/write calls cannot express these multi-step transactions and timing constraints.
- Protocol requirements: I2C read operations require I2C_M_NO_RD_ACK flags; SPI write-then-read operations require mandatory inter-transfer delays and CS assertion across phases.
While regmap provides valuable synchronization, debugfs, and abstraction benefits, standard I2C/SPI regmap buses cannot handle these requirements.
Custom regmap implementation is technically possible via IO accessors, but demands complex command routing logic and only partially supports paging. It would essentially recreate the existing controller functions while forcing them into register semantics they don't naturally fit.
The current explicit I2C/SPI approach directly expresses the hardware's actual command structure and maintains proper controller abstraction.
Changes in v5:
- dt-bindings: set $ref: /schemas/leds/common.yaml# at the node level
- dt-bindings: add constraints to max_/default_brightness properties
- dt-bindings: clarify digit positions are numbered left-to-right
- dt-bindings: reorder the schema sections to 'dependencies',
'required', 'allOf'
- dt-bindings: leds: add default-brightness to leds/common.yaml
- core: rename prfx to prefix in TM16XX_CTRL_BRIGHTNESS macro
- core: drop i2c/spi client union in favor of to_i2c_client/to_spi_device
- core: rename controller grids/segments to avoid 7-seg confusion
- core: remove tm16xx_digit_segment and simplify tm16xx_digit structs
- core: drop tm16xx sysfs attributes in favor of line-display library
- core: rename tm16xx_parse_dt to tm16xx_parse_fwnode
- core: replace manual child count with fwnode_get_child_node_count
- core: use __free(fwnode_handle) instead of fwnode_handle_put
- core: remove of.h include and duplicated logic of main led label
- core: use devm_ variant of mutex_init
- core: drop kernel-doc for well-established meaning functions
- i2c/spi: remove redundant NULL initializers
- i2c/spi: remove CONFIG_OF preprocessor conditions
- i2c/spi: drop usage of of_match_ptr
- i2c/spi: fix CONFIG_I2C=m, CONFIG_SPI=y, CONFIG_TM16XX=y edge case reported by kernel test robot (late v3 feedback)
- all: rely on explicit rather than transitive includes
- all: review signed types usage consistency
- all: use 'if (ret)' where there is no positive return
- all: apply relaxed line wrap, allowing over 80 column width
- all: remove info and debug messages
- all: update copyright year to 2025
Changes in v4:
- Split MAINTAINERS patch into each specific patch
- Document ABI of sysfs driver attributes
- Remove kernel-doc of obvious Linux core driver model APIs
- dt-bindings: Drop obvious comments that schema tells by itself
- dt-bindings: Gather canonical compatible strings in a single enum
- dt-bindings: Clarify top-level logical led DT node name/label property
- dt:bindings: Replace refs to input properties with allOf
- Split driver patch and code file for better reviewability
- Refactor into separate i2c and spi glue driver modules
- Drop driver name macro constant in favor of explicit string literals
- Revise to use bit shifts for values and GENMASK/BIT for bit positions
- Format TM16XX_CTRL_BRIGHTNESS on one line
- Drop default_value module param in favor of Kconfig compile time option
- Fix for_each_key name and expressions
- Replace manual mutex locking with scoped_guard
- Move scancode declaration to avoid mix with code
- Remove unnecessary ret initialization
- Remove ENOMEM error message
- Replace probe error messages by dev_err_probe
- Remove keypad failed probe cleanup to avoid devm anti-pattern confusion
- Switch to non-devm led registration to avoid anti-pattern confusion
- Replace u16 in favor of unsigned int for controller data
Changes in v3:
- Update vendor prefixes with documented rationale, in a single patch, per maintainer feedback
- Refine device tree bindings per maintainer feedback:
* Update compatible string ordering and fallback logic
* Improve YAML descriptions for clarity and 80-column wrapping
* Replace digit-specific properties with clearer digits container node
* Add required constraints for properties in container nodes
* Clarify addressing schemes for LED icons and digits
* Fix conditional SPI properties handling
* Document rationale for spi-3wire property
* Expand DT examples to cover typical and transposed display layouts
- Code reformat from clang-format to kernel style per maintainer feedback
- Fix conditional CONFIG_I2C/_SPI compilation issues per kernel test robot
- Add keypad scanning with configurable keymap (new feature)
- Add support for TM1638 controller extending hardware compatibility
- Add support for default and maximum brightness properties
- Fix multi-instance device handling and add optional label property
- Allocate DMA-safe SPI buffer for hardware compatibility
- Enhance error handling with comprehensive kernel-doc documentation
- Remove sysfs runtime reconfiguration, enforce device tree-only
Changes in v2:
- Fix duplicate label in dt-bindings examples
- Rename device tree property prefixes to use titanmec vendor prefix
Jean-François Lessard (7):
dt-bindings: vendor-prefixes: Add fdhisi, titanmec, princeton,
winrise, wxicore
dt-bindings: leds: add default-brightness property to common.yaml
dt-bindings: auxdisplay: add Titan Micro Electronics TM16xx
auxdisplay: Add TM16xx 7-segment LED matrix display controllers driver
auxdisplay: TM16xx: Add keypad support for scanning matrix keys
auxdisplay: TM16xx: Add support for I2C-based controllers
auxdisplay: TM16xx: Add support for SPI-based controllers
.../bindings/auxdisplay/titanmec,tm16xx.yaml | 463 ++++++++++++++++++ .../devicetree/bindings/leds/common.yaml | 6 + .../devicetree/bindings/vendor-prefixes.yaml | 10 + MAINTAINERS | 11 + drivers/auxdisplay/Kconfig | 50 ++ drivers/auxdisplay/Makefile | 5 + drivers/auxdisplay/tm16xx.h | 197 ++++++++ drivers/auxdisplay/tm16xx_core.c | 463 ++++++++++++++++++ drivers/auxdisplay/tm16xx_i2c.c | 332 +++++++++++++ drivers/auxdisplay/tm16xx_keypad.c | 196 ++++++++ drivers/auxdisplay/tm16xx_spi.c | 397 +++++++++++++++ 11 files changed, 2130 insertions(+) create mode 100644 Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml create mode 100644 drivers/auxdisplay/tm16xx.h create mode 100644 drivers/auxdisplay/tm16xx_core.c create mode 100644 drivers/auxdisplay/tm16xx_i2c.c create mode 100644 drivers/auxdisplay/tm16xx_keypad.c create mode 100644 drivers/auxdisplay/tm16xx_spi.c
Signature · 1 line
2.43.0
PATCH v5 1/7 dt-bindings: vendor-prefixes: Add fdhisi, titanmec, princeton, winrise, wxicore
Add vendor prefixes of chip manufacturers supported by the TM16xx 7-segment LED matrix display controllers driver:
- fdhisi: Fuzhou Fuda Hisi Microelectronics Co., Ltd.
- titanmec: Shenzhen Titan Micro Electronics Co., Ltd.
- princeton: Princeton Technology Corp.
- winrise: Shenzhen Winrise Technology Co., Ltd.
- wxicore: Wuxi i-Core Electronics Co., Ltd.
The titanmec prefix is based on the company's domain name titanmec.com. The remaining prefixes are based on company names, as these manufacturers either lack active .com domains or their .com domains are occupied by unrelated businesses.
The fdhisi and titanmec prefixes were originally identified by Andreas Färber.
---
CC: Andreas Färber <[email protected]>
Documentation/devicetree/bindings/vendor-prefixes.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +10 -0
@@ -542,6 +542,8 @@ patternProperties: description: Fastrax Oy "^fcs,.*": description: Fairchild Semiconductor + "^fdhisi,.*": + description: Fuzhou Fuda Hisi Microelectronics Co., Ltd. "^feixin,.*": description: Shenzhen Feixin Photoelectic Co., Ltd "^feiyang,.*":
@@ -1235,6 +1237,8 @@ patternProperties: description: Prime View International (PVI) "^primux,.*": description: Primux Trading, S.L. + "^princeton,.*": + description: Princeton Technology Corp. "^probox2,.*": description: PROBOX2 (by W2COMP Co., Ltd.) "^pri,.*":
@@ -1569,6 +1573,8 @@ patternProperties: description: Texas Instruments "^tianma,.*": description: Tianma Micro-electronics Co., Ltd. + "^titanmec,.*": + description: Shenzhen Titan Micro Electronics Co., Ltd. "^tlm,.*": description: Trusted Logic Mobility "^tmt,.*":
@@ -1726,6 +1732,8 @@ patternProperties: description: Wingtech Technology Co., Ltd. "^winlink,.*": description: WinLink Co., Ltd + "^winrise,.*": + description: Shenzhen Winrise Technology Co., Ltd. "^winsen,.*": description: Winsen Corp. "^winstar,.*":
@@ -1742,6 +1750,8 @@ patternProperties: description: Wobo "^wolfvision,.*": description: WolfVision GmbH + "^wxicore,.*": + description: Wuxi i-Core Electronics Co., Ltd. "^x-powers,.*": description: X-Powers "^xen,.*":
Signature · 1 line
2.43.0
PATCH v5 2/7 dt-bindings: leds: add default-brightness property to common.yaml
In reply to Jean-François LessardAdd default-brightness property to leds/common.yaml to establish a single canonical definition for LED brightness initialization.
The property is currently defined locally in leds/leds-pwm.yaml and is needed by auxdisplay/titanmec,tm16xx.yaml. Properties should be defined in only one location to avoid type inconsistencies across bindings.
--- Documentation/devicetree/bindings/leds/common.yaml | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/leds/common.yaml +6 -0
@@ -173,6 +173,12 @@ properties: led-max-microamp. $ref: /schemas/types.yaml#/definitions/uint32 + default-brightness: + description: + Brightness to be set if LED's default state is on. Used only during + initialization. If the option is not set then max brightness is used. + $ref: /schemas/types.yaml#/definitions/uint32 + panic-indicator: description: This property specifies that the LED should be used, if at all possible,
Signature · 1 line
2.43.0
Re: [PATCH v5 2/7] dt-bindings: leds: add default-brightness property to common.yaml
Quoted 12 lines · Jean-François Lessard
Add default-brightness property to
leds/common.yamlto establish a single canonical definition for LED brightness initialization.The property is currently defined locally in
leds/leds-pwm.yamland is needed byauxdisplay/titanmec,tm16xx.yaml. Properties should be defined in only one location to avoid type inconsistencies across bindings.Signed-off-by Jean-François Lessard <[email protected]>--- Documentation/devicetree/bindings/leds/common.yaml | 6 ++++++ 1 file changed, 6 insertions(+)
Re: (subset) [PATCH v5 2/7] dt-bindings: leds: add default-brightness property to common.yaml
In reply to Jean-François LessardQuoted 8 lines · Jean-François Lessard
Add default-brightness property to
leds/common.yamlto establish a single canonical definition for LED brightness initialization.The property is currently defined locally in
leds/leds-pwm.yamland is needed byauxdisplay/titanmec,tm16xx.yaml. Properties should be defined in only one location to avoid type inconsistencies across bindings.[...]
Applied, thanks!
[2/7] dt-bindings: leds: add default-brightness property to common.yaml
commit: bdbc4e3a018afcfbf29d50a5953df013bc98eb1c
--
Lee Jones [李琼斯]
PATCH v5 3/7 dt-bindings: auxdisplay: add Titan Micro Electronics TM16xx
In reply to Jean-François LessardAdd documentation for TM16xx-compatible 7-segment LED display controllers with keyscan.
---
Notes:
The 'segments' property is intentionally not vendor-prefixed as it defines a generic hardware description concept applicable to any 7-segment display controller. The property describes the fundamental grid/segment coordinate mapping that is controller-agnostic and could be reused by other LED matrix display bindings. Similar to how 'gpios' describes GPIO connections generically, 'segments' describes segment connections in a standardized way using uint32-matrix format.
The property uses explicit coordinate pairs to handle real-world hardware variations. Some board manufacturers use standard layouts (same grid, different segments per digit) while others use transposed layouts (same segment, different grids per digit). The coordinate-pair approach accommodates both patterns without requiring separate arrays or boolean flags, as confirmed acceptable by DT maintainers.
.../bindings/auxdisplay/titanmec,tm16xx.yaml | 463 ++++++++++++++++++ MAINTAINERS | 5 + 2 files changed, 468 insertions(+) create mode 100644 Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml new file +463 -0
@@ -0,0 +1,463 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/auxdisplay/titanmec,tm16xx.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Auxiliary displays based on TM16xx and compatible LED controllers + +maintainers: + - Jean-François Lessard <[email protected]> + +description: | + LED matrix controllers used in auxiliary display devices that drive individual + LED icons and 7-segment digit groups through a grid/segment addressing scheme. + Controllers manage a matrix of LEDs organized as grids (columns/banks in + vendor datasheets) and segments (rows/bit positions in vendor datasheets). + Maximum brightness and grid/segment indices are controller-specific. + Controller-specific maximum are validated in the driver. + + The controller is agnostic of the display layout. Board-specific LED wiring is + described through child nodes that specify grid/segment coordinates for + individual icons and segment mapping for 7-segment digits. + + The bindings use separate 'leds' and 'digits' containers to accommodate + different addressing schemes: + - LEDs use 2-cell addressing (grid, segment) for matrix coordinates + - Digits use 1-cell addressing with explicit segment mapping + + The controller node exposes a logical LED-like control for the aggregate + display brightness. Child nodes describe individual icons and 7-seg digits. + The top-level control supports only label and brightness-related properties + and does not support other common LED properties such as color or function. + Child LED nodes use the standard LED binding. + + Optional keypad scanning is supported when both 'linux,keymap' and + 'poll-interval' properties are specified. + +properties: + compatible: + oneOf: + - items: + - enum: + - fdhisi,fd628 + - princeton,pt6964 + - wxicore,aip1628 + - const: titanmec,tm1628 + - items: + - enum: + - wxicore,aip1618 + - const: titanmec,tm1618 + - items: + - enum: + - fdhisi,fd650 + - wxicore,aip650 + - const: titanmec,tm1650 + - enum: + - fdhisi,fd620 + - fdhisi,fd655 + - fdhisi,fd6551 + - titanmec,tm1618 + - titanmec,tm1620 + - titanmec,tm1628 + - titanmec,tm1638 + - titanmec,tm1650 + - winrise,hbs658 + + reg: + maxItems: 1 + + label: + description: + The label for the top-level LED. If omitted, the label is taken from the + node name (excluding the unit address). It has to uniquely identify a + device, i.e. no other LED class device can be assigned the same label. + + max-brightness: + minimum: 0 # 0=off + maximum: 8 # Maximum across all TM16xx controllers + description: + Normally the maximum brightness is determined by the hardware and this + property is not required. This property is used to put a software limit + on the brightness apart from what the driver says, as it could happen + that a LED can be made so bright that it gets damaged or causes damage + due to restrictions in a specific system, such as mounting conditions. + + default-brightness: + minimum: 0 # 0=off + maximum: 8 # Maximum across all TM16xx controllers + description: + Brightness to be set if LED's default state is on. Used only during + initialization. If the option is not set then max brightness is used. + + digits: + type: object + description: Container for 7-segment digit group definitions + additionalProperties: false + + properties: + "#address-cells": + const: 1 + "#size-cells": + const: 0 + + patternProperties: + "^digit@[0-9]+$": + type: object + unevaluatedProperties: false + + properties: + reg: + description: + Digit position identifier numbered sequentially left-to-right, + with reg=0 representing the leftmost digit position as displayed + to the user. + maxItems: 1 + + segments: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + description: | + Array of grid/segment coordinate pairs for each 7-segment position. + Each entry is <grid segment> mapping to standard 7-segment positions + in order: a, b, c, d, e, f, g + + Standard 7-segment layout: + aaa + f b + f b + ggg + e c + e c + ddd + items: + items: + - description: Grid index + - description: Segment index + minItems: 7 + maxItems: 7 + + required: + - reg + - segments + + leds: + type: object + description: Container for individual LED icon definitions + additionalProperties: false + + properties: + "#address-cells": + const: 2 + "#size-cells": + const: 0 + + patternProperties: + "^led@[0-9]+,[0-9]+$": + type: object + $ref: /schemas/leds/common.yaml# + unevaluatedProperties: false + + properties: + reg: + description: + Grid and segment indices as <grid segment> of this individual LED icon + + required: + - reg + +dependencies: + poll-interval: + - linux,keymap + linux,keymap: + - poll-interval + autorepeat: + - linux,keymap + - poll-interval + +required: + - compatible + - reg + +allOf: + - $ref: /schemas/leds/common.yaml# + properties: + color: false + function: false + function-enumerator: false + - $ref: /schemas/input/input.yaml# + - $ref: /schemas/input/matrix-keymap.yaml# + # SPI controllers require 3-wire (combined MISO/MOSI line) + - if: + properties: + compatible: + contains: + enum: + - fdhisi,fd620 + - fdhisi,fd628 + - princeton,pt6964 + - titanmec,tm1618 + - titanmec,tm1620 + - titanmec,tm1628 + - titanmec,tm1638 + - wxicore,aip1618 + - wxicore,aip1628 + then: + $ref: /schemas/spi/spi-peripheral-props.yaml# + properties: + spi-3wire: true + required: + - spi-3wire + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/leds/common.h> + + // I2C example: Magicsee N5 TV box with fd655 controller + i2c { + #address-cells = <1>; + #size-cells = <0>; + + display@24 { + reg = <0x24>; + compatible = "fdhisi,fd655"; + + digits { + #address-cells = <1>; + #size-cells = <0>; + digit@0 { + reg = <0>; + segments = <1 3>, <1 4>, <1 5>, <1 0>, <1 1>, <1 2>, <1 6>; + }; + digit@1 { + reg = <1>; + segments = <2 3>, <2 4>, <2 5>, <2 0>, <2 1>, <2 2>, <2 6>; + }; + digit@2 { + reg = <2>; + segments = <3 3>, <3 4>, <3 5>, <3 0>, <3 1>, <3 2>, <3 6>; + }; + digit@3 { + reg = <3>; + segments = <4 3>, <4 4>, <4 5>, <4 0>, <4 1>, <4 2>, <4 6>; + }; + }; + + leds { + #address-cells = <2>; + #size-cells = <0>; + led@0,0 { + reg = <0 0>; + function = LED_FUNCTION_ALARM; + }; + led@0,1 { + reg = <0 1>; + function = LED_FUNCTION_USB; + }; + led@0,2 { + reg = <0 2>; + function = "play"; + }; + led@0,3 { + reg = <0 3>; + function = "pause"; + }; + led@0,4 { + reg = <0 4>; + function = "colon"; + }; + led@0,5 { + reg = <0 5>; + function = LED_FUNCTION_LAN; + }; + led@0,6 { + reg = <0 6>; + function = LED_FUNCTION_WLAN; + }; + }; + }; + }; + + - | + #include <dt-bindings/input/input.h> + + // SPI example: TM1638 module with keypad support + spi { + #address-cells = <1>; + #size-cells = <0>; + + display@0 { + reg = <0>; + compatible = "titanmec,tm1638"; + spi-3wire; + spi-lsb-first; + spi-max-frequency = <500000>; + + label = "tm1638"; + default-brightness = <2>; + max-brightness = <4>; + poll-interval = <100>; + linux,keymap = <MATRIX_KEY(2, 0, KEY_F1) + MATRIX_KEY(2, 2, KEY_F2) + MATRIX_KEY(2, 4, KEY_F3) + MATRIX_KEY(2, 6, KEY_F4) + MATRIX_KEY(2, 1, KEY_F5) + MATRIX_KEY(2, 3, KEY_F6) + MATRIX_KEY(2, 5, KEY_F7) + MATRIX_KEY(2, 7, KEY_F8)>; + + digits { + #address-cells = <1>; + #size-cells = <0>; + + digit@0 { + reg = <0>; + segments = <7 0>, <7 1>, <7 2>, <7 3>, <7 4>, <7 5>, <7 6>; + }; + + digit@1 { + reg = <1>; + segments = <6 0>, <6 1>, <6 2>, <6 3>, <6 4>, <6 5>, <6 6>; + }; + + digit@2 { + reg = <2>; + segments = <5 0>, <5 1>, <5 2>, <5 3>, <5 4>, <5 5>, <5 6>; + }; + + digit@3 { + reg = <3>; + segments = <4 0>, <4 1>, <4 2>, <4 3>, <4 4>, <4 5>, <4 6>; + }; + + digit@4 { + reg = <4>; + segments = <3 0>, <3 1>, <3 2>, <3 3>, <3 4>, <3 5>, <3 6>; + }; + + digit@5 { + reg = <5>; + segments = <2 0>, <2 1>, <2 2>, <2 3>, <2 4>, <2 5>, <2 6>; + }; + + digit@6 { + reg = <6>; + segments = <1 0>, <1 1>, <1 2>, <1 3>, <1 4>, <1 5>, <1 6>; + }; + + digit@7 { + reg = <7>; + segments = <0 0>, <0 1>, <0 2>, <0 3>, <0 4>, <0 5>, <0 6>; + }; + }; + + leds { + #address-cells = <2>; + #size-cells = <0>; + + led@0,7 { + reg = <0 7>; + }; + + led@1,7 { + reg = <1 7>; + }; + + led@2,7 { + reg = <2 7>; + }; + + led@3,7 { + reg = <3 7>; + }; + + led@4,7 { + reg = <4 7>; + }; + + led@5,7 { + reg = <5 7>; + }; + + led@6,7 { + reg = <6 7>; + }; + + led@7,7 { + reg = <7 7>; + }; + }; + }; + }; + + - | + #include <dt-bindings/leds/common.h> + + // SPI example: X96 Max with transposed layout (fd628 with tm1628 fallback) + spi { + #address-cells = <1>; + #size-cells = <0>; + + display@0 { + reg = <0>; + compatible = "fdhisi,fd628", "titanmec,tm1628"; + spi-3wire; + spi-lsb-first; + spi-max-frequency = <500000>; + + digits { + #address-cells = <1>; + #size-cells = <0>; + digit@0 { + reg = <0>; + segments = <0 7>, <1 7>, <2 7>, <3 7>, <4 7>, <5 7>, <6 7>; + }; + digit@1 { + reg = <1>; + segments = <0 6>, <1 6>, <2 6>, <3 6>, <4 6>, <5 6>, <6 6>; + }; + digit@2 { + reg = <2>; + segments = <0 5>, <1 5>, <2 5>, <3 5>, <4 5>, <5 5>, <6 5>; + }; + digit@3 { + reg = <3>; + segments = <0 4>, <1 4>, <2 4>, <3 4>, <4 4>, <5 4>, <6 4>; + }; + }; + + leds { + #address-cells = <2>; + #size-cells = <0>; + led@0,3 { + reg = <0 3>; + function = "apps"; + }; + led@1,3 { + reg = <1 3>; + function = "setup"; + }; + led@2,3 { + reg = <2 3>; + function = LED_FUNCTION_USB; + }; + led@3,3 { + reg = <3 3>; + function = LED_FUNCTION_SD; + }; + led@4,3 { + reg = <4 3>; + function = "colon"; + }; + led@5,3 { + reg = <5 3>; + function = "hdmi"; + }; + led@6,3 { + reg = <6 3>; + function = "video"; + }; + }; + }; + };
MAINTAINERS +5 -0
@@ -25441,6 +25441,11 @@ W: http://sourceforge.net/projects/tlan/ F: Documentation/networking/device_drivers/ethernet/ti/tlan.rst F: drivers/net/ethernet/ti/tlan.* +TM16XX-COMPATIBLE LED CONTROLLERS DISPLAY DRIVER +M: Jean-François Lessard <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml + TMIO/SDHI MMC DRIVER M: Wolfram Sang <[email protected]> L: [email protected]
Signature · 1 line
2.43.0
Re: [PATCH v5 3/7] dt-bindings: auxdisplay: add Titan Micro Electronics TM16xx
Quoted 128 lines · Jean-François Lessard
Add documentation for TM16xx-compatible 7-segment LED display controllers with keyscan.
Signed-off-by Jean-François Lessard <[email protected]>---
Notes:
The 'segments' property is intentionally not vendor-prefixed as it defines a generic hardware description concept applicable to any 7-segment display controller. The property describes the fundamental grid/segment coordinate mapping that is controller-agnostic and could be reused by other LED matrix display bindings. Similar to how 'gpios' describes GPIO connections generically, 'segments' describes segment connections in a standardized way using uint32-matrix format.The property uses explicit coordinate pairs to handle real-world hardware variations. Some board manufacturers use standard layouts (same grid, different segments per digit) while others use transposed layouts (same segment, different grids per digit). The coordinate-pair approach accommodates both patterns without requiring separate arrays or boolean flags, as confirmed acceptable by DT maintainers.
.../bindings/auxdisplay/titanmec,tm16xx.yaml | 463 ++++++++++++++++++ MAINTAINERS | 5 + 2 files changed, 468 insertions(+) create mode 100644 Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yamlDocumentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml new file +95
-0@@ -0,0 +1,463 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/auxdisplay/titanmec,tm16xx.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Auxiliary displays based on TM16xx and compatible LED controllers + +maintainers: + - Jean-François Lessard <[email protected]> + +description: | + LED matrix controllers used in auxiliary display devices that drive individual + LED icons and 7-segment digit groups through a grid/segment addressing scheme. + Controllers manage a matrix of LEDs organized as grids (columns/banks in + vendor datasheets) and segments (rows/bit positions in vendor datasheets). + Maximum brightness and grid/segment indices are controller-specific. + Controller-specific maximum are validated in the driver. + + The controller is agnostic of the display layout. Board-specific LED wiring is + described through child nodes that specify grid/segment coordinates for + individual icons and segment mapping for 7-segment digits. + + The bindings use separate 'leds' and 'digits' containers to accommodate + different addressing schemes: + - LEDs use 2-cell addressing (grid, segment) for matrix coordinates + - Digits use 1-cell addressing with explicit segment mapping + + The controller node exposes a logical LED-like control for the aggregate + display brightness. Child nodes describe individual icons and 7-seg digits. + The top-level control supports only label and brightness-related properties + and does not support other common LED properties such as color or function. + Child LED nodes use the standard LED binding. + + Optional keypad scanning is supported when both 'linux,keymap' and + 'poll-interval' properties are specified. + +properties: + compatible: + oneOf: + - items: + - enum: + - fdhisi,fd628 + - princeton,pt6964 + - wxicore,aip1628 + - const: titanmec,tm1628 + - items: + - enum: + - wxicore,aip1618 + - const: titanmec,tm1618 + - items: + - enum: + - fdhisi,fd650 + - wxicore,aip650 + - const: titanmec,tm1650 + - enum: + - fdhisi,fd620 + - fdhisi,fd655 + - fdhisi,fd6551 + - titanmec,tm1618 + - titanmec,tm1620 + - titanmec,tm1628 + - titanmec,tm1638 + - titanmec,tm1650 + - winrise,hbs658 + + reg: + maxItems: 1 + + label: + description: + The label for the top-level LED. If omitted, the label is taken from the + node name (excluding the unit address). It has to uniquely identify a + device, i.e. no other LED class device can be assigned the same label. + + max-brightness: + minimum: 0 # 0=off + maximum: 8 # Maximum across all TM16xx controllers + description: + Normally the maximum brightness is determined by the hardware and this + property is not required. This property is used to put a software limit + on the brightness apart from what the driver says, as it could happen + that a LED can be made so bright that it gets damaged or causes damage + due to restrictions in a specific system, such as mounting conditions. + + default-brightness: + minimum: 0 # 0=off + maximum: 8 # Maximum across all TM16xx controllers + description: + Brightness to be set if LED's default state is on. Used only during + initialization. If the option is not set then max brightness is used. + + digits: + type: object + description: Container for 7-segment digit group definitions
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml line 105
Quoted 10 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml new file +10
-0+ additionalProperties: false + + properties: + "#address-cells": + const: 1 + "#size-cells": + const: 0 + + patternProperties: + "^digit@[0-9]+$":
Unit addresses are typically hex, so: [0-9a-f]+
Quoted 40 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml new file +40
-0+ type: object + unevaluatedProperties: false + + properties: + reg: + description: + Digit position identifier numbered sequentially left-to-right, + with reg=0 representing the leftmost digit position as displayed + to the user. + maxItems: 1 + + segments: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + description: | + Array of grid/segment coordinate pairs for each 7-segment position. + Each entry is <grid segment> mapping to standard 7-segment positions + in order: a, b, c, d, e, f, g + + Standard 7-segment layout: + aaa + f b + f b + ggg + e c + e c + ddd + items: + items: + - description: Grid index + - description: Segment index + minItems: 7 + maxItems: 7 + + required: + - reg + - segments + + leds: + type: object + description: Container for individual LED icon definitions
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml line 155
Quoted 10 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml new file +10
-0+ additionalProperties: false + + properties: + "#address-cells": + const: 2 + "#size-cells": + const: 0 + + patternProperties: + "^led@[0-9]+,[0-9]+$":
Again, hex please.
I assume this is <grid>,<segment>? Please add a description for the node and say that.
Quoted 42 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml new file +42
-0+ type: object + $ref: /schemas/leds/common.yaml# + unevaluatedProperties: false + + properties: + reg: + description: + Grid and segment indices as <grid segment> of this individual LED icon + + required: + - reg + +dependencies: + poll-interval: + - linux,keymap + linux,keymap: + - poll-interval + autorepeat: + - linux,keymap + - poll-interval + +required: + - compatible + - reg + +allOf: + - $ref: /schemas/leds/common.yaml# + properties: + color: false + function: false + function-enumerator: false + - $ref: /schemas/input/input.yaml# + - $ref: /schemas/input/matrix-keymap.yaml# + # SPI controllers require 3-wire (combined MISO/MOSI line) + - if: + properties: + compatible: + contains: + enum: + - fdhisi,fd620 + - fdhisi,fd628 + - princeton,pt6964
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml line 207
Quoted 10 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml new file +10
-0+ - titanmec,tm1618 + - titanmec,tm1620 + - titanmec,tm1628 + - titanmec,tm1638 + - wxicore,aip1618 + - wxicore,aip1628 + then: + $ref: /schemas/spi/spi-peripheral-props.yaml# + properties: + spi-3wire: true
You can drop properties.
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml line 209
Quoted 2 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml new file +2
-0+ required: + - spi-3wire
With those nits fixed,
Re: [PATCH v5 3/7] dt-bindings: auxdisplay: add Titan Micro Electronics TM16xx
Le 1 octobre 2025 22 h 44 min 31 s HAE, Rob Herring <[email protected]> a écrit :
Quoted 4 lines · Jean-François Lessard
Quoted 3 lines
Add documentation for TM16xx-compatible 7-segment LED display controllers with keyscan.
...
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml new file +8
-0+ + digits: + type: object + description: Container for 7-segment digit group definitions + additionalProperties: false + + properties: + "#address-cells":
Quoted 9 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml line 105
Quoted 6 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml new file +6
-0+ const: 1 + "#size-cells": + const: 0 + + patternProperties: + "^digit@[0-9]+$":Unit addresses are typically hex, so: [0-9a-f]+
Acknowledged. Will change to hex pattern.
Quoted 44 lines
Quoted 44 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml new file +44
-0+ type: object + unevaluatedProperties: false + + properties: + reg: + description: + Digit position identifier numbered sequentially left-to-right, + with reg=0 representing the leftmost digit position as displayed + to the user. + maxItems: 1 + + segments: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + description: | + Array of grid/segment coordinate pairs for each 7-segment position. + Each entry is <grid segment> mapping to standard 7-segment positions + in order: a, b, c, d, e, f, g + + Standard 7-segment layout: + aaa + f b + f b + ggg + e c + e c + ddd + items: + items: + - description: Grid index + - description: Segment index + minItems: 7 + maxItems: 7 + + required: + - reg + - segments + + leds: + type: object + description: Container for individual LED icon definitions + additionalProperties: false + + properties: + "#address-cells":
Quoted 9 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml line 155
Quoted 6 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml new file +6
-0+ const: 2 + "#size-cells": + const: 0 + + patternProperties: + "^led@[0-9]+,[0-9]+$":Again, hex please.
Acknowledged. Will change to hex pattern.
Quoted 3 lines
I assume this is <grid>,<segment>? Please add a description for the node and say that.
Yes this is <grid>,<segment>. Will add description.
Quoted 46 lines
Quoted 46 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml new file +46
-0+ type: object + $ref: /schemas/leds/common.yaml# + unevaluatedProperties: false + + properties: + reg: + description: + Grid and segment indices as <grid segment> of this individual LED icon + + required: + - reg + +dependencies: + poll-interval: + - linux,keymap + linux,keymap: + - poll-interval + autorepeat: + - linux,keymap + - poll-interval + +required: + - compatible + - reg + +allOf: + - $ref: /schemas/leds/common.yaml# + properties: + color: false + function: false + function-enumerator: false + - $ref: /schemas/input/input.yaml# + - $ref: /schemas/input/matrix-keymap.yaml# + # SPI controllers require 3-wire (combined MISO/MOSI line) + - if: + properties: + compatible: + contains: + enum: + - fdhisi,fd620 + - fdhisi,fd628 + - princeton,pt6964 + - titanmec,tm1618 + - titanmec,tm1620 + - titanmec,tm1628 + - titanmec,tm1638
Quoted 9 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml line 207
Quoted 6 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml new file +6
-0+ - wxicore,aip1618 + - wxicore,aip1628 + then: + $ref: /schemas/spi/spi-peripheral-props.yaml# + properties: + spi-3wire: trueYou can drop properties.
The issue is spi-3wire is defined in the child node of spi/spi-controller.yaml, not in spi-peripheral-props.yaml.
Removing properties did not pass dt validation. Am I missing something?
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ required: + - spi-3wireWith those nits fixed,
Reviewed-by Rob Herring (Arm) <[email protected]>
Thank you!
Re: [PATCH v5 3/7] dt-bindings: auxdisplay: add Titan Micro Electronics TM16xx
Hi Rob,
Thank you for the review and Reviewed-by tag. I've addressed all your feedback except one item that's causing validation issues.
Le 1 octobre 2025 22 h 58 min 38 s HAE, "Jean-François Lessard" <[email protected]> a écrit :
Quoted 4 lines
Le 1 octobre 2025 22 h 44 min 31 s HAE, Rob Herring <[email protected]> a écrit :
Quoted 3 lines · Jean-François Lessard
Quoted 2 lines
Add documentation for TM16xx-compatible 7-segment LED display controllers with keyscan.
...
Quoted 32 lines
Quoted 22 lines
Quoted 22 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml new file +22
-0+ +allOf: + - $ref: /schemas/leds/common.yaml# + properties: + color: false + function: false + function-enumerator: false + - $ref: /schemas/input/input.yaml# + - $ref: /schemas/input/matrix-keymap.yaml# + # SPI controllers require 3-wire (combined MISO/MOSI line) + - if: + properties: + compatible: + contains: + enum: + - fdhisi,fd620 + - fdhisi,fd628 + - princeton,pt6964 + - titanmec,tm1618 + - titanmec,tm1620 + - titanmec,tm1628 + - titanmec,tm1638Quoted 9 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml line 207
Quoted 6 lines
Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml new file +6
-0+ - wxicore,aip1618 + - wxicore,aip1628 + then: + $ref: /schemas/spi/spi-peripheral-props.yaml# + properties: + spi-3wire: trueYou can drop properties.
Quoted 5 lines
The issue is spi-3wire is defined in the child node of
spi/spi-controller.yaml, not inspi-peripheral-props.yaml.Removing properties did not pass dt validation. Am I missing something?
You suggested dropping "properties:" in the SPI 3-wire section:
then:
$ref: /schemas/spi/spi-peripheral-props.yaml#
spi-3wire: true
required:
- spi-3wire
However, this causes dt_binding_check to fail with:
'spi-3wire' is not one of ['$ref', 'additionalItems', ... 'properties', 'required', 'then', ...]
Unevaluated properties are not allowed ('spi-3wire' was unexpected)
It appears the schema requires "properties:" to recognize spi-3wire as a property constraint rather than a schema keyword. Should I keep the properties wrapper, or is there a different way to structure this that I'm missing?
Quoted 7 lines
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ required: + - spi-3wireWith those nits fixed,
Reviewed-by Rob Herring (Arm) <[email protected]>
Thanks for clarifying.
Best regards,
Jean-François
PATCH v5 4/7 auxdisplay: Add TM16xx 7-segment LED matrix display controllers driver
In reply to Jean-François LessardAdd driver for TM16xx family LED controllers and compatible chips from multiple vendors including Titan Micro, Fuda Hisi, i-Core, Princeton, and Winrise. These controllers drive 7-segment digits and individual LED icons through either I2C or SPI buses.
Successfully tested on various ARM TV boxes including H96 Max, Magicsee N5, Tanix TX3 Mini, Tanix TX6, X92, and X96 Max across different SoC platforms (Rockchip, Amlogic, Allwinner).
---
Notes:
checkpatch reports false positives that are intentionally ignored:
BIT_MACRO: bit shifts are used for field values while GENMASK/BIT are used for bit positions per semantic convention
LED registration uses non-devm variant on-purpose to allow explicit unregistration on device removal, ensuring LED triggers are immediately stopped. This prevents stale LED trigger activity from continuing after the hardware is gone, avoiding the need for complex state tracking in brightness callbacks.
MAINTAINERS | 3 + drivers/auxdisplay/Kconfig | 9 + drivers/auxdisplay/Makefile | 2 + drivers/auxdisplay/tm16xx.h | 172 ++++++++++++ drivers/auxdisplay/tm16xx_core.c | 459 +++++++++++++++++++++++++++++++ 5 files changed, 645 insertions(+) create mode 100644 drivers/auxdisplay/tm16xx.h create mode 100644 drivers/auxdisplay/tm16xx_core.c
MAINTAINERS +3 -0
@@ -25444,7 +25444,10 @@ F: drivers/net/ethernet/ti/tlan.* TM16XX-COMPATIBLE LED CONTROLLERS DISPLAY DRIVER M: Jean-François Lessard <[email protected]> S: Maintained +F: Documentation/ABI/testing/sysfs-class-leds-tm16xx F: Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml +F: drivers/auxdisplay/tm16xx.h +F: drivers/auxdisplay/tm16xx_core.c TMIO/SDHI MMC DRIVER M: Wolfram Sang <[email protected]>
drivers/auxdisplay/Kconfig +9 -0
@@ -526,6 +526,15 @@ config SEG_LED_GPIO This driver can also be built as a module. If so, the module will be called seg-led-gpio. +config TM16XX + tristate + select LEDS_CLASS + select LEDS_TRIGGERS + select LINEDISP + select NEW_LEDS + help + Core TM16XX-compatible 7-segment LED controllers module + # # Character LCD with non-conforming interface section #
drivers/auxdisplay/Makefile +2 -0
@@ -16,3 +16,5 @@ obj-$(CONFIG_LINEDISP) += line-display.o obj-$(CONFIG_MAX6959) += max6959.o obj-$(CONFIG_PARPORT_PANEL) += panel.o obj-$(CONFIG_SEG_LED_GPIO) += seg-led-gpio.o +obj-$(CONFIG_TM16XX) += tm16xx.o +tm16xx-y += tm16xx_core.o
drivers/auxdisplay/tm16xx.h new file +172 -0
172 lines not on this page · raw message
drivers/auxdisplay/tm16xx_core.c new file +459 -0
459 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 8 lines · Jean-François Lessard
Add driver for TM16xx family LED controllers and compatible chips from multiple vendors including Titan Micro, Fuda Hisi, i-Core, Princeton, and Winrise. These controllers drive 7-segment digits and individual LED icons through either I2C or SPI buses.
Successfully tested on various ARM TV boxes including H96 Max, Magicsee N5, Tanix TX3 Mini, Tanix TX6, X92, and X96 Max across different SoC platforms (Rockchip, Amlogic, Allwinner).
...
Quoted 1 line
+config TM16XX
Hmm... After applying this patch there will be no compile test coverage.
drivers/auxdisplay/Kconfig config SEG_LED_GPIO · line 530
Quoted 1 line
drivers/auxdisplay/Kconfig +1
-0+ tristate
IIRC there is a trick how to achieve that by modifying a tristate line to be visible depending on the other options.
E.g.,drivers/dpll/zl3073x/Kconfig:4: tristate "Microchip Azurite DPLL/PTP/SyncE devices" if COMPILE_TEST
drivers/auxdisplay/Kconfig config SEG_LED_GPIO · line 536
Quoted 6 lines
drivers/auxdisplay/Kconfig +6
-0+ select LEDS_CLASS + select LEDS_TRIGGERS + select LINEDISP + select NEW_LEDS + help + Core TM16XX-compatible 7-segment LED controllers module
Please, elaborate a bit more here. Usually we expect ~3 lines of description to be a minimum.
...
drivers/auxdisplay/tm16xx.h line 10
Quoted 2 lines
drivers/auxdisplay/tm16xx.h new file +2
-0+#ifndef _TM16XX_H +#define _TM16XX_H
+ bits.h
Review
Quoted 2 lines
(quoted diff) +2
-0+#include <linux/bitfield.h> +#include <linux/leds.h>
+ mutex.h
Quoted 1 line
+#include <
linux/workqueue.h>
+ types.h
...
drivers/auxdisplay/tm16xx.h line 93
Quoted 6 lines
drivers/auxdisplay/tm16xx.h new file +6
-0+#define FD655_CMD_CTRL 0x48 +#define FD655_CMD_ADDR 0x66 +#define FD655_CTRL_BR_MASK GENMASK(6, 5) +#define FD655_CTRL_ON (1 << 0) + +#define FD6551_CMD_CTRL 0x48
Do we need a duplicate? Yes, bitfields can be different, but since the register is called the same, I would leave only one register offset definition.
...
Quoted 9 lines
drivers/auxdisplay/tm16xx.h new file +9
-0+/** +* DOC: struct tm16xx_controller - Controller-specific operations and limits +* @max_grids: Maximum number of grids supported by the controller. +* @max_segments: Maximum number of segments supported by the controller. +* @max_brightness: Maximum brightness level supported by the controller. +* @max_key_rows: Maximum number of key input rows supported by the controller. +* @max_key_cols: Maximum number of key input columns supported by the controller. +* @init: Pointer to controller mode/brightness configuration function. +* @data: Pointer to function writing display data to the controller.
drivers/auxdisplay/tm16xx.h line 125
Quoted 10 lines
drivers/auxdisplay/tm16xx.h new file +10
-0+* @keys: Pointer to function reading controller key state into bitmap. +* +* Holds function pointers and limits for controller-specific operations. +*/ +struct tm16xx_controller { +const u8 max_grids; +const u8 max_segments; +const u8 max_brightness; +const u8 max_key_rows; +const u8 max_key_cols;
What are const above supposed to achieve?
Quoted 4 lines
drivers/auxdisplay/tm16xx.h new file +4
-0+int (*const init)(struct tm16xx_display *display); +int (*const data)(struct tm16xx_display *display,u8 index,unsigned int grid); +int (*const keys)(struct tm16xx_display *display); +};
...
drivers/auxdisplay/tm16xx.h line 151
Quoted 2 lines
drivers/auxdisplay/tm16xx.h new file +2
-0+struct tm16xx_display { +struct device *dev;
Missing forward declaration.
Quoted 18 lines
drivers/auxdisplay/tm16xx.h new file +17
-0+const struct tm16xx_controller *controller; +struct linedisp linedisp; +u8 *spi_buffer; +u8 num_hwgrid; +u8 num_hwseg; +struct led_classdev main_led; +struct tm16xx_led *leds; +u8 num_leds; +struct tm16xx_digit *digits; +u8 num_digits; +struct work_struct flush_init; +struct work_struct flush_display; +int flush_status; +struct mutex lock;/* prevents concurrent work operations */ + unsigned long *state; +}; +#endif /* _TM16XX_H */
...
drivers/auxdisplay/tm16xx_core.c line 18
Quoted 10 lines
drivers/auxdisplay/tm16xx_core.c new file +10
-0+#include <linux/bitfield.h> +#include <linux/bitmap.h> +#include <linux/cleanup.h> +#include <linux/container_of.h> +#include <linux/device.h> +#include <linux/leds.h> +#include <linux/map_to_7segment.h> +#include <linux/module.h> +#include <linux/property.h> +#include <linux/sysfs.h>
+ types.h
drivers/auxdisplay/tm16xx.h line 16
Quoted 3 lines
drivers/auxdisplay/tm16xx.h new file +2
-0+#include <linux/workqueue.h> +#include "line-display.h"
I would add a blank line here as well.
Quoted 1 line
+#include "
tm16xx.h"
...
drivers/auxdisplay/tm16xx_core.c line 27
Quoted 2 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+#define linedisp_to_tm16xx (display) \ + container_of(display, struct tm16xx_display, linedisp)
One line, we are using 100 limit here.
...
Quoted 6 lines
+/**
+ *tm16xx_set_seg()- Set the display state for a specific grid/segment
+ * @display: pointer totm16xx_display
+ * @hwgrid: grid index
+ * @hwseg: segment index
+ * @on: true to turn on, false to turn off
Can also be %true and %false. This helps the rendering to use different font settings for the constants (where applicable).
drivers/auxdisplay/tm16xx_core.c line 74
Quoted 5 lines
+ */
drivers/auxdisplay/tm16xx_core.c new file +4
-0+static inline void tm16xx_set_seg (const struct tm16xx_display *display, +const u8 hwgrid,const u8 hwseg,const bool on) +{ +assign_bit (hwgrid * display->num_hwseg + hwseg, display->state, on);
Do you need an atomic call here? Perhaps __assign_bit() would suffice,
Quoted 1 line
+}
...
drivers/auxdisplay/tm16xx_core.c line 88
Quoted 5 lines
drivers/auxdisplay/tm16xx_core.c new file +5
-0+static inline unsigned int tm16xx_get_grid (const struct tm16xx_display *display, +const unsigned int index) +{ +return bitmap_read (display->state, index * display->num_hwseg, + display->num_hwseg);
One line.
Quoted 1 line
+}
...
drivers/auxdisplay/tm16xx_core.c line 100
Quoted 5 lines
drivers/auxdisplay/tm16xx_core.c new file +5
-0+static void tm16xx_display_flush_init (struct work_struct *work) +{ +struct tm16xx_display *display =container_of (work, + struct tm16xx_display, + flush_init);
I slightly prefer
struct tm16xx_display *display = container_of(work, struct tm16xx_display, flush_init);
Or even a single line.
drivers/auxdisplay/tm16xx_core.c line 111
Quoted 11 lines
drivers/auxdisplay/tm16xx_core.c new file +11
-0+int ret; + +if (display->controller->init) { + scoped_guard(mutex, &display->lock) { + ret = display->controller->init (display); + display->flush_status = ret; + } +if (ret) +dev_err (display->dev, +"Failed to configure controller: %d\n" , ret); + }
First of all, I'm not sure what the lock is protecting. Here you allow "init" to be whatever, while in the below code the "data" is protected.
Second, I haven't seen changes in this function later in the series, so perhaps drop the indentation by negating conditional?
drivers/auxdisplay/tm16xx_core.c line 116
Quoted 5 lines
drivers/auxdisplay/tm16xx_core.c new file +4
-0+} +/** +* tm16xx_display_flush_data() - Workqueue to update display data to controller +* @work: pointer to work_struct
Perhaps add a small description and explain that this is interrupted if an error occurs and that error will be stored for further use by upper layers.
Does the same apply to the above function?
drivers/auxdisplay/tm16xx_core.c line 126
Quoted 10 lines
+ */
drivers/auxdisplay/tm16xx_core.c new file +8
-0+static void tm16xx_display_flush_data (struct work_struct *work) +{ +struct tm16xx_display *display =container_of (work, + struct tm16xx_display, + flush_display); +unsigned int grid, i; +int ret =0 ; + scoped_guard(mutex, &display->lock) {
As per above, and here AFAICS guard()() will suit better.
Quoted 16 lines
drivers/auxdisplay/tm16xx_core.c new file +16
-0+if (display->controller->data) { +for (i =0 ; i < display->num_hwgrid; i++) { + grid =tm16xx_get_grid (display, i); + ret = display->controller->data (display, i, grid); +if (ret) { +dev_err (display->dev, +"Failed to write display data: %d\n" , + ret); +break ; + } + } + } + + display->flush_status = ret; + } +}
...
drivers/auxdisplay/tm16xx_core.c line 150
Quoted 2 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+static void tm16xx_brightness_set (struct led_classdev *led_cdev, +enum led_brightness brightness)
One line
...
drivers/auxdisplay/tm16xx_core.c line 164
Quoted 2 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+static void tm16xx_led_set (struct led_classdev *led_cdev, +enum led_brightness value)
Ditto.
...
drivers/auxdisplay/tm16xx_core.c line 179
Quoted 8 lines
drivers/auxdisplay/tm16xx_core.c new file +7
-0+static int tm16xx_display_value (struct tm16xx_display *display,const char *buf,size_t count) +{ +struct linedisp *linedisp = &display->linedisp; +struct linedisp_map *map = linedisp->map; +struct tm16xx_digit *digit; +unsigned int i, j; +int seg_pattern;
Hmm... Should it be signed?
drivers/auxdisplay/tm16xx_core.c line 182
Quoted 3 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+bool val; +for (i =0 ; i < display->num_digits && i < count; i++) {
This means "whatever is smaller", perhaps make it clearer by using min() ?
Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c new file +4
-0+ digit = &display->digits[i]; + seg_pattern =map_to_seg7 (&map->map.seg7, buf[i]); + +for (j =0 ; j <TM16XX_DIGIT_SEGMENTS ; j++) {
drivers/auxdisplay/tm16xx_core.c line 196
Quoted 10 lines
drivers/auxdisplay/tm16xx_core.c new file +10
-0+ val = seg_pattern &BIT (j); +tm16xx_set_seg (display, digit->hwgrids[j], digit->hwsegs[j], val); + } + } + +for (; i < display->num_digits; i++) { + digit = &display->digits[i]; +for (j =0 ; j <TM16XX_DIGIT_SEGMENTS ; j++) +tm16xx_set_seg (display, digit->hwgrids[j], digit->hwsegs[j],0 ); + }
Or unite these two for-loops into a single one with i < count conditional embedded?
for (j = 0; j < TM16XX_DIGIT_SEGMENTS; j++) {
if (i < count)
val = seg_pattern & BIT(j);
else
val = 0;
tm16xx_set_seg(display, digit->hwgrids[j], digit->hwsegs[j], val);
}?
Quoted 3 lines
drivers/auxdisplay/tm16xx_core.c new file +3
-0+schedule_work (&display->flush_display); +return 0 ; +}
...
Quoted 10 lines
drivers/auxdisplay/tm16xx_core.c new file +10
-0+static int tm16xx_parse_fwnode (struct device *dev,struct tm16xx_display *display) +{ +struct tm16xx_led *led; +struct tm16xx_digit *digit; +unsigned int max_hwgrid =0 , max_hwseg =0 ; +unsigned int i, j; +int ret; +u32 segments[TM16XX_DIGIT_SEGMENTS *2 ]; +u32 reg[2 ]; +
drivers/auxdisplay/tm16xx_core.c line 248
Quoted 10 lines
drivers/auxdisplay/tm16xx_core.c new file +9
-0+ struct fwnode_handle *digits_node __free(fwnode_handle) = +device_get_named_child_node (dev,"digits" ); + struct fwnode_handle *leds_node __free(fwnode_handle) = +device_get_named_child_node (dev,"leds" ); + +/* parse digits */ +if (digits_node) { + display->num_digits =fwnode_get_child_node_count (digits_node); +if (display->num_digits) {
Drop an indentation level by splitting this to a helper.
Quoted 10 lines
drivers/auxdisplay/tm16xx_core.c new file +10
-0+ display->digits =devm_kcalloc (dev, display->num_digits, +sizeof (*display->digits), +GFP_KERNEL ); +if (!display->digits) +return -ENOMEM ; + + i =0 ; +fwnode_for_each_available_child_node_scoped (digits_node, child) { + digit = &display->digits[i]; +
drivers/auxdisplay/tm16xx_core.c line 267
Quoted 10 lines
drivers/auxdisplay/tm16xx_core.c new file +9
-0+ ret =fwnode_property_read_u32 (child,"reg" , reg); +if (ret) +return ret; + + ret =fwnode_property_read_u32_array (child, +"segments" , segments, +TM16XX_DIGIT_SEGMENTS *2 ); +if (ret <0 ) +return ret;
Why '< 0'? Here it's definitely not a counting call, so it should never return positive in this case.
Quoted 7 lines
drivers/auxdisplay/tm16xx_core.c new file +7
-0+ +for (j =0 ; j <TM16XX_DIGIT_SEGMENTS ; ++j) { + digit->hwgrids[j] = segments[2 * j]; + digit->hwsegs[j] = segments[2 * j +1 ]; + max_hwgrid =umax (max_hwgrid, digit->hwgrids[j]); + max_hwseg =umax (max_hwseg, digit->hwsegs[j]); + }
drivers/auxdisplay/tm16xx_core.c line 284
Quoted 10 lines
drivers/auxdisplay/tm16xx_core.c new file +9
-0+ i++; + } + } + } + +/* parse leds */ +if (leds_node) { + display->num_leds =fwnode_get_child_node_count (leds_node); +if (display->num_leds) {
Ditto.
drivers/auxdisplay/tm16xx_core.c line 295
Quoted 11 lines
drivers/auxdisplay/tm16xx_core.c new file +11
-0+ display->leds =devm_kcalloc (dev, display->num_leds, +sizeof (*display->leds), +GFP_KERNEL ); +if (!display->leds) +return -ENOMEM ; + + i =0 ; +fwnode_for_each_available_child_node_scoped (leds_node, child) { + led = &display->leds[i]; + ret =fwnode_property_read_u32_array (child,"reg" , reg,2 ); +if (ret <0 )
Ditto,.
Quoted 28 lines
drivers/auxdisplay/tm16xx_core.c new file +28
-0+return ret; + + led->hwgrid = reg[0 ]; + led->hwseg = reg[1 ]; + max_hwgrid =umax (max_hwgrid, led->hwgrid); + max_hwseg =umax (max_hwseg, led->hwseg); + i++; + } + } + } + +if (max_hwgrid >= display->controller->max_grids) { +dev_err (dev,"grid %u exceeds controller max_grids %u\n" , + max_hwgrid, display->controller->max_grids); +return -EINVAL ; + } + +if (max_hwseg >= display->controller->max_segments) { +dev_err (dev,"segment %u exceeds controller max_segments %u\n" , + max_hwseg, display->controller->max_segments); +return -EINVAL ; + } + + display->num_hwgrid = max_hwgrid +1 ; + display->num_hwseg = max_hwseg +1 ; + +return 0 ; +}
...
Quoted 6 lines
+/**
+ *tm16xx_probe()- Probe and initialize display device, register LEDs
+ * @display: pointer totm16xx_display
+ *
+ * Return: 0 on success, negative error code on failure
+ */
Unneeded kernel-doc.
drivers/auxdisplay/tm16xx_core.c line 335
Quoted 5 lines
drivers/auxdisplay/tm16xx_core.c new file +5
-0+int tm16xx_probe (struct tm16xx_display *display) +{ +struct device *dev = display->dev; +struct led_classdev *main = &display->main_led; +struct led_init_data led_init = {0 };
'0' is not needed.
Quoted 7 lines
drivers/auxdisplay/tm16xx_core.c new file +7
-0+struct fwnode_handle *leds_node; +struct tm16xx_led *led; +unsigned int nbits, i; +int ret; + + ret =tm16xx_parse_fwnode (dev, display); +if (ret)
drivers/auxdisplay/tm16xx_core.c line 352
Quoted 10 lines
drivers/auxdisplay/tm16xx_core.c new file +10
-0+return dev_err_probe (dev, ret,"Failed to parse device tree\n" ); + + nbits =tm16xx_led_nbits (display); + display->state =devm_bitmap_zalloc (dev, nbits,GFP_KERNEL ); +if (!display->state) +return -ENOMEM ; + + ret =devm_mutex_init (display->dev, &display->lock); +if (ret) +return dev_err_probe (dev, ret,"Failed to initialize mutex\n" );
I believe it's ENOMEM here, so we don't need an error message.
drivers/auxdisplay/tm16xx_core.c line 355
Quoted 2 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+INIT_WORK (&display->flush_init, tm16xx_display_flush_init); +INIT_WORK (&display->flush_display, tm16xx_display_flush_data);
devm-helpers.h have something for this case, I believe.
drivers/auxdisplay/tm16xx_core.c line 358
Quoted 2 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+/* Initialize main LED properties */ + led_init.fwnode =dev_fwnode (dev);/* apply label property */
I didn't get a comment. This not only about label, but for entire set of properties that led framework can consume.
drivers/auxdisplay/tm16xx_core.c line 362
Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c new file +4
-0+ main->max_brightness = display->controller->max_brightness; +device_property_read_u32 (dev,"max-brightness" , &main->max_brightness); + main->max_brightness =umin (main->max_brightness, + display->controller->max_brightness);
Hmm... Why 'u' variant of macro?
drivers/auxdisplay/tm16xx_core.c line 366
Quoted 3 lines
drivers/auxdisplay/tm16xx_core.c new file +3
-0+ main->brightness = main->max_brightness; +device_property_read_u32 (dev,"default-brightness" , &main->brightness); + main->brightness =umin (main->brightness, main->max_brightness);
Ditto.
Given a comment about propagating fwnode, why do we need all this? Doesn't led core take care of these properties as well?
Quoted 8 lines
drivers/auxdisplay/tm16xx_core.c new file +8
-0+ main->brightness_set = tm16xx_brightness_set; + main->flags =LED_RETAIN_AT_SHUTDOWN |LED_CORE_SUSPENDRESUME ; + +/* Register individual LEDs from device tree */ + ret =led_classdev_register_ext (dev, main, &led_init); +if (ret) +return dev_err_probe (dev, ret,"Failed to register main LED\n" ); +
drivers/auxdisplay/tm16xx_core.c line 384
Quoted 10 lines
drivers/auxdisplay/tm16xx_core.c new file +9
-0+ i =0 ; + led_init.devicename =dev_name (main->dev); + led_init.devname_mandatory = true; + led_init.default_label ="led" ; + leds_node =device_get_named_child_node (dev,"leds" ); +fwnode_for_each_available_child_node_scoped (leds_node, child) { + led_init.fwnode = child; + led = &display->leds[i]; + led->cdev.max_brightness =1 ;
That should be set to default by the led core based on the property value, not the case?
drivers/auxdisplay/tm16xx_core.c line 388
Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c new file +4
-0+ led->cdev.brightness_set = tm16xx_led_set; + led->cdev.flags =LED_RETAIN_AT_SHUTDOWN |LED_CORE_SUSPENDRESUME ; + + ret =led_classdev_register_ext (dev, &led->cdev, &led_init);
Why not devm_led_*()?
Quoted 11 lines
drivers/auxdisplay/tm16xx_core.c new file +11
-0+if (ret) { +dev_err_probe (dev, ret,"Failed to register LED %s\n" , + led->cdev.name); + goto unregister_leds; + } + + i++; + } + + ret =tm16xx_display_init (display); +if (ret) {
drivers/auxdisplay/tm16xx_core.c line 409
Quoted 10 lines
drivers/auxdisplay/tm16xx_core.c new file +9
-0+dev_err_probe (dev, ret,"Failed to initialize display\n" ); + goto unregister_leds; + } + ret =linedisp_attach (&display->linedisp, display->main_led.dev, + display->num_digits, &tm16xx_linedisp_ops); +if (ret) { +dev_err_probe (dev, ret,"Failed to initialize line-display\n" ); + goto unregister_leds; + }
If we haven't yet devm for this, it can be
1) introduced, OR
2) wrapped to become a such (see devm_add_action_or_reset() usage).
drivers/auxdisplay/tm16xx_core.c line 420
Quoted 10 lines
drivers/auxdisplay/tm16xx_core.c new file +10
-0+return 0 ; + +unregister_leds: +while (i--) +led_classdev_unregister (&display->leds[i].cdev); + +led_classdev_unregister (main); +return ret; +} +EXPORT_SYMBOL_NS (tm16xx_probe,"TM16XX" );
Needs to be namespaced _GPL variant. Same for all exports.
Quoted 4 lines
+/**
+ *tm16xx_remove()- Remove display, unregister LEDs, blank output
+ * @display: pointer totm16xx_display
+ */
Unneeded kernel-doc.
drivers/auxdisplay/tm16xx_core.c line 437
Quoted 12 lines
drivers/auxdisplay/tm16xx_core.c new file +11
-0+void tm16xx_remove (struct tm16xx_display *display) +{ +unsigned int nbits =tm16xx_led_nbits (display); +struct tm16xx_led *led; + +linedisp_detach (display->main_led.dev); +/* +* Unregister LEDs first to immediately stop trigger activity. +* This prevents LED triggers from attempting to access hardware +* after it's been disconnected or driver unloaded. +*/
After switching to devm_*() this comment won't be needed (besides that it will come orphaned).
Quoted 7 lines
drivers/auxdisplay/tm16xx_core.c new file +7
-0+for (int i =0 ; i < display->num_leds; i++) { + led = &display->leds[i]; +led_classdev_unregister (&led->cdev); + } +led_classdev_unregister (&display->main_led); + +/* Clear display state */
drivers/auxdisplay/tm16xx_core.c line 454
Quoted 10 lines
drivers/auxdisplay/tm16xx_core.c new file +10
-0+bitmap_zero (display->state, nbits); +schedule_work (&display->flush_display); +flush_work (&display->flush_display); + +/* Turn off display */ + display->main_led.brightness =LED_OFF ; +schedule_work (&display->flush_init); +flush_work (&display->flush_init); +} +EXPORT_SYMBOL_NS (tm16xx_remove,"TM16XX" );
_GPL
Signature · 2 lines
With Best Regards, Andy Shevchenko
Le 31 octobre 2025 05 h 41 min 44 s HAE, Andy Shevchenko <[email protected]> a écrit :
Quoted 16 lines · Jean-François Lessard
Quoted 8 lines
Add driver for TM16xx family LED controllers and compatible chips from multiple vendors including Titan Micro, Fuda Hisi, i-Core, Princeton, and Winrise. These controllers drive 7-segment digits and individual LED icons through either I2C or SPI buses.
Successfully tested on various ARM TV boxes including H96 Max, Magicsee N5, Tanix TX3 Mini, Tanix TX6, X92, and X96 Max across different SoC platforms (Rockchip, Amlogic, Allwinner).
...
Quoted 1 line
+config TM16XX
Hmm... After applying this patch there will be no compile test coverage.
Quoted 8 lines
drivers/auxdisplay/Kconfig config SEG_LED_GPIO · line 530
Quoted 1 line
drivers/auxdisplay/Kconfig +1
-0+ tristateIIRC there is a trick how to achieve that by modifying a tristate line to be visible depending on the other options.
E.g.,
drivers/dpll/zl3073x/Kconfig:4: tristate "Microchip Azurite DPLL/PTP/SyncE devices" ifCOMPILE_TEST
Acknowledged. I'll add COMPILE_TEST:
tristate "TM16xx LED matrix display controllers" if COMPILE_TEST
Quoted 10 lines
drivers/auxdisplay/Kconfig config SEG_LED_GPIO · line 536
Quoted 6 lines
drivers/auxdisplay/Kconfig +6
-0+ select LEDS_CLASS + select LEDS_TRIGGERS + select LINEDISP + select NEW_LEDS + help + Core TM16XX-compatible 7-segment LED controllers modulePlease, elaborate a bit more here. Usually we expect ~3 lines of description to be a minimum.
I'll expand to ~3 lines describing driver purpose and supported hardware families.
Quoted 7 lines
...
drivers/auxdisplay/tm16xx.h line 10
Quoted 2 lines
drivers/auxdisplay/tm16xx.h new file +2
-0+#ifndef _TM16XX_H +#define _TM16XX_H+
bits.h
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+#include <linux/bitfield.h> +#include <linux/leds.h>+
mutex.hQuoted 1 line
+#include <
linux/workqueue.h>+
types.h
Will add missing includes.
Quoted 12 lines
...
drivers/auxdisplay/tm16xx.h line 93
Quoted 6 lines
drivers/auxdisplay/tm16xx.h new file +6
-0+#define FD655_CMD_CTRL 0x48 +#define FD655_CMD_ADDR 0x66 +#define FD655_CTRL_BR_MASK GENMASK(6, 5) +#define FD655_CTRL_ON (1 << 0) + +#define FD6551_CMD_CTRL 0x48Do we need a duplicate? Yes, bitfields can be different, but since the register is called the same, I would leave only one register offset definition.
Acknowledged. I'll consolidate to single definition since they share the same offset.
Quoted 15 lines
...
Quoted 13 lines
+/**
+ * DOC: structtm16xx_controller- Controller-specific operations and limits
+ * @max_grids: Maximum number of grids supported by the controller.
+ * @max_segments: Maximum number of segments supported by the controller.
+ * @max_brightness: Maximum brightness level supported by the controller.
+ * @max_key_rows: Maximum number of key input rows supported by the controller.
+ * @max_key_cols: Maximum number of key input columns supported by the controller.
+ * @init: Pointer to controller mode/brightness configuration function.
+ * @data: Pointer to function writing display data to the controller.
+ * @keys: Pointer to function reading controller key state into bitmap.
+ *
+ * Holds function pointers and limits for controller-specific operations.
+ */
Quoted 9 lines
drivers/auxdisplay/tm16xx.h line 125
Quoted 6 lines
drivers/auxdisplay/tm16xx.h new file +6
-0+struct tm16xx_controller { +const u8 max_grids; +const u8 max_segments; +const u8 max_brightness; +const u8 max_key_rows; +const u8 max_key_cols;What are const above supposed to achieve?
My intent was to mark these as immutable controller characteristics, but I'll remove them as they don't provide meaningful protection here.
Quoted 7 lines
Quoted 4 lines
drivers/auxdisplay/tm16xx.h new file +4
-0+int (*const init)(struct tm16xx_display *display); +int (*const data)(struct tm16xx_display *display,u8 index,unsigned int grid); +int (*const keys)(struct tm16xx_display *display); +};...
Quoted 5 lines
drivers/auxdisplay/tm16xx.h line 151
Quoted 2 lines
drivers/auxdisplay/tm16xx.h new file +2
-0+struct tm16xx_display { +struct device *dev;Missing forward declaration.
Will add forward declaration.
Quoted 21 lines
Quoted 18 lines
drivers/auxdisplay/tm16xx.h new file +17
-0+const struct tm16xx_controller *controller; +struct linedisp linedisp; +u8 *spi_buffer; +u8 num_hwgrid; +u8 num_hwseg; +struct led_classdev main_led; +struct tm16xx_led *leds; +u8 num_leds; +struct tm16xx_digit *digits; +u8 num_digits; +struct work_struct flush_init; +struct work_struct flush_display; +int flush_status; +struct mutex lock;/* prevents concurrent work operations */ + unsigned long *state; +}; +#endif /* _TM16XX_H */ ...
Quoted 13 lines
drivers/auxdisplay/tm16xx_core.c line 18
Quoted 10 lines
drivers/auxdisplay/tm16xx_core.c new file +10
-0+#include <linux/bitfield.h> +#include <linux/bitmap.h> +#include <linux/cleanup.h> +#include <linux/container_of.h> +#include <linux/device.h> +#include <linux/leds.h> +#include <linux/map_to_7segment.h> +#include <linux/module.h> +#include <linux/property.h> +#include <linux/sysfs.h> +
types.h
Will add missing include.
Quoted 6 lines
drivers/auxdisplay/tm16xx.h line 16
Quoted 3 lines
drivers/auxdisplay/tm16xx.h new file +2
-0+#include <linux/workqueue.h> +#include "line-display.h" I would add a blank line here as well.
Will add blank line.
Quoted 9 lines
Quoted 1 line
+#include "
tm16xx.h"...
drivers/auxdisplay/tm16xx_core.c line 27
Quoted 2 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+#define linedisp_to_tm16xx (display) \ + container_of(display, struct tm16xx_display, linedisp)One line, we are using 100 limit here.
Will format to single line within 100 char limit.
Quoted 9 lines
...
Quoted 6 lines
+/**
+ *tm16xx_set_seg()- Set the display state for a specific grid/segment
+ * @display: pointer totm16xx_display
+ * @hwgrid: grid index
+ * @hwseg: segment index
+ * @on: true to turn on, false to turn off
Quoted 3 lines
Can also be %true and %false. This helps the rendering to use different font settings for the constants (where applicable).
Will use kernel-doc formatting conventions.
Quoted 8 lines
drivers/auxdisplay/tm16xx_core.c line 74
Quoted 5 lines
+ */
drivers/auxdisplay/tm16xx_core.c new file +4
-0+static inline void tm16xx_set_seg (const struct tm16xx_display *display, +const u8 hwgrid,const u8 hwseg,const bool on) +{ +assign_bit (hwgrid * display->num_hwseg + hwseg, display->state, on);Do you need an atomic call here? Perhaps
__assign_bit()would suffice,
Keeping assign_bit(), it's required here. Two distinct concurrency scenarios exist:
- Bitmap: Multiple LED triggers (network, timer) + userspace write to display->state concurrently -> need atomic ops
- Hardware: Mutex serializes different hardware operations (flush_init, flush_display, keypad polling) that can race
The mutex doesn't eliminate bitmap concurrency needs, they're orthogonal concerns.
Quoted 4 lines
Quoted 1 line
+}
...
Quoted 8 lines
drivers/auxdisplay/tm16xx_core.c line 88
Quoted 5 lines
drivers/auxdisplay/tm16xx_core.c new file +5
-0+static inline unsigned int tm16xx_get_grid (const struct tm16xx_display *display, +const unsigned int index) +{ +return bitmap_read (display->state, index * display->num_hwseg, + display->num_hwseg);One line.
Will format to single line within 100 char limit.
Quoted 12 lines
Quoted 1 line
+}
...
drivers/auxdisplay/tm16xx_core.c line 100
Quoted 5 lines
drivers/auxdisplay/tm16xx_core.c new file +5
-0+static void tm16xx_display_flush_init (struct work_struct *work) +{ +struct tm16xx_display *display =container_of (work, + struct tm16xx_display, + flush_init);I slightly prefer
Quoted 5 lines
struct tm16xx_display *display = container_of(work, struct tm16xx_display, flush_init);Or even a single line.
Will format to single line within 100 char limit.
Quoted 16 lines
drivers/auxdisplay/tm16xx_core.c line 111
Quoted 12 lines
drivers/auxdisplay/tm16xx_core.c new file +11
-0+int ret; + +if (display->controller->init) { + scoped_guard(mutex, &display->lock) { + ret = display->controller->init (display); + display->flush_status = ret; + } +if (ret) +dev_err (display->dev, +"Failed to configure controller: %d\n" , ret); + }First of all, I'm not sure what the lock is protecting. Here you allow "init" to be whatever, while in the below code the "data" is protected.
The mutex serializes different hardware operation types occurring concurrently:
brightness changes (flush_init), display updates (flush_display), and keypad polling. The workqueue prevents concurrent execution of the same work, not different operations.
Quoted 3 lines
Second, I haven't seen changes in this function later in the series, so perhaps drop the indentation by negating conditional?
Will refactor with early return to reduce indentation.
Quoted 11 lines
drivers/auxdisplay/tm16xx_core.c line 116
Quoted 5 lines
drivers/auxdisplay/tm16xx_core.c new file +4
-0+} +/** +* tm16xx_display_flush_data() - Workqueue to update display data to controller +* @work: pointer to work_struct Perhaps add a small description and explain that this is interrupted if an error occurs and that error will be stored for further use by upper layers.
Does the same apply to the above function?
Will add descriptions explaining error handling behavior for both functions.
Quoted 9 lines
Quoted 8 lines
+ */
drivers/auxdisplay/tm16xx_core.c new file +7
-0+static void tm16xx_display_flush_data (struct work_struct *work) +{ +struct tm16xx_display *display =container_of (work, + struct tm16xx_display, + flush_display); +unsigned int grid, i; +int ret =0 ;
Quoted 4 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ scoped_guard(mutex, &display->lock) {As per above, and here AFAICS guard()() will suit better.
Will change to guard()() here.
Quoted 19 lines
Quoted 16 lines
drivers/auxdisplay/tm16xx_core.c new file +16
-0+if (display->controller->data) { +for (i =0 ; i < display->num_hwgrid; i++) { + grid =tm16xx_get_grid (display, i); + ret = display->controller->data (display, i, grid); +if (ret) { +dev_err (display->dev, +"Failed to write display data: %d\n" , + ret); +break ; + } + } + } + + display->flush_status = ret; + } +}...
Quoted 5 lines
drivers/auxdisplay/tm16xx_core.c line 150
Quoted 2 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+static void tm16xx_brightness_set (struct led_classdev *led_cdev, +enum led_brightness brightness)One line
Will format to single line within 100 char limit.
Quoted 7 lines
...
drivers/auxdisplay/tm16xx_core.c line 164
Quoted 2 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+static void tm16xx_led_set (struct led_classdev *led_cdev, +enum led_brightness value)Ditto.
Will format to single line within 100 char limit.
Quoted 9 lines
...
Quoted 6 lines
drivers/auxdisplay/tm16xx_core.c new file +6
-0+static int tm16xx_display_value (struct tm16xx_display *display,const char *buf,size_t count) +{ +struct linedisp *linedisp = &display->linedisp; +struct linedisp_map *map = linedisp->map; +struct tm16xx_digit *digit; +unsigned int i, j;
Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c line 179
Quoted 1 line
drivers/auxdisplay/tm16xx_core.c new file +1
-0+int seg_pattern;Hmm... Should it be signed?
Keeping signed, map_to_seg7() returns int per its API contract.
Quoted 31 lines
drivers/auxdisplay/tm16xx_core.c line 182
Quoted 3 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+bool val; +for (i =0 ; i < display->num_digits && i < count; i++) {This means "whatever is smaller", perhaps make it clearer by using
min()?Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c new file +4
-0+ digit = &display->digits[i]; + seg_pattern =map_to_seg7 (&map->map.seg7, buf[i]); + +for (j =0 ; j <TM16XX_DIGIT_SEGMENTS ; j++) {drivers/auxdisplay/tm16xx_core.c line 196
Quoted 10 lines
drivers/auxdisplay/tm16xx_core.c new file +10
-0+ val = seg_pattern &BIT (j); +tm16xx_set_seg (display, digit->hwgrids[j], digit->hwsegs[j], val); + } + } + +for (; i < display->num_digits; i++) { + digit = &display->digits[i]; +for (j =0 ; j <TM16XX_DIGIT_SEGMENTS ; j++) +tm16xx_set_seg (display, digit->hwgrids[j], digit->hwsegs[j],0 ); + }Or unite these two for-loops into a single one with i < count conditional embedded?
for (j = 0; j < TM16XX_DIGIT_SEGMENTS; j++) { if (i < count) val = seg_pattern & BIT(j); else val = 0; tm16xx_set_seg(display, digit->hwgrids[j], digit->hwsegs[j], val); }
Quoted 2 lines
?
Will merge loops with embedded conditional as suggested.
Quoted 25 lines
Quoted 3 lines
drivers/auxdisplay/tm16xx_core.c new file +3
-0+schedule_work (&display->flush_display); +return 0 ; +}...
Quoted 18 lines
drivers/auxdisplay/tm16xx_core.c new file +18
-0+static int tm16xx_parse_fwnode (struct device *dev,struct tm16xx_display *display) +{ +struct tm16xx_led *led; +struct tm16xx_digit *digit; +unsigned int max_hwgrid =0 , max_hwseg =0 ; +unsigned int i, j; +int ret; +u32 segments[TM16XX_DIGIT_SEGMENTS *2 ]; +u32 reg[2 ]; + + struct fwnode_handle *digits_node __free(fwnode_handle) = +device_get_named_child_node (dev,"digits" ); + struct fwnode_handle *leds_node __free(fwnode_handle) = +device_get_named_child_node (dev,"leds" ); + +/* parse digits */ +if (digits_node) { + display->num_digits =fwnode_get_child_node_count (digits_node);
Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c line 248
Quoted 1 line
drivers/auxdisplay/tm16xx_core.c new file +1
-0+if (display->num_digits) {Drop an indentation level by splitting this to a helper.
Will extract digits node/num parsing into helper function.
Quoted 18 lines
Quoted 17 lines
drivers/auxdisplay/tm16xx_core.c new file +17
-0+ display->digits =devm_kcalloc (dev, display->num_digits, +sizeof (*display->digits), +GFP_KERNEL ); +if (!display->digits) +return -ENOMEM ; + + i =0 ; +fwnode_for_each_available_child_node_scoped (digits_node, child) { + digit = &display->digits[i]; + + ret =fwnode_property_read_u32 (child,"reg" , reg); +if (ret) +return ret; + + ret =fwnode_property_read_u32_array (child, +"segments" , segments, +TM16XX_DIGIT_SEGMENTS *2 );
Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (ret < 0) + return ret;Why '< 0'? Here it's definitely not a counting call, so it should never return positive in this case.
Keeping if (ret < 0). While usage with non-NULL buffer won't return positive values, fwnode_property_read_u32_array() documentation explicitly states it can return count when buffer is NULL. Using < 0 is the defensive, API-compliant pattern that matches the function signature.
Quoted 16 lines
Quoted 15 lines
drivers/auxdisplay/tm16xx_core.c new file +15
-0+ +for (j =0 ; j <TM16XX_DIGIT_SEGMENTS ; ++j) { + digit->hwgrids[j] = segments[2 * j]; + digit->hwsegs[j] = segments[2 * j +1 ]; + max_hwgrid =umax (max_hwgrid, digit->hwgrids[j]); + max_hwseg =umax (max_hwseg, digit->hwsegs[j]); + } + i++; + } + } + } + +/* parse leds */ +if (leds_node) { + display->num_leds =fwnode_get_child_node_count (leds_node);
Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c line 284
Quoted 1 line
drivers/auxdisplay/tm16xx_core.c new file +1
-0+if (display->num_leds) {Ditto.
Will extract leds node/num parsing into helper function.
Quoted 5 lines
Quoted 5 lines
drivers/auxdisplay/tm16xx_core.c new file +5
-0+ display->leds =devm_kcalloc (dev, display->num_leds, +sizeof (*display->leds), +GFP_KERNEL ); +if (!display->leds) +return -ENOMEM ;
Quoted 9 lines
drivers/auxdisplay/tm16xx_core.c line 295
Quoted 6 lines
drivers/auxdisplay/tm16xx_core.c new file +6
-0+ + i =0 ; +fwnode_for_each_available_child_node_scoped (leds_node, child) { + led = &display->leds[i]; + ret =fwnode_property_read_u32_array (child,"reg" , reg,2 ); +if (ret <0 )Ditto,.
As per above.
Quoted 31 lines
Quoted 28 lines
drivers/auxdisplay/tm16xx_core.c new file +28
-0+return ret; + + led->hwgrid = reg[0 ]; + led->hwseg = reg[1 ]; + max_hwgrid =umax (max_hwgrid, led->hwgrid); + max_hwseg =umax (max_hwseg, led->hwseg); + i++; + } + } + } + +if (max_hwgrid >= display->controller->max_grids) { +dev_err (dev,"grid %u exceeds controller max_grids %u\n" , + max_hwgrid, display->controller->max_grids); +return -EINVAL ; + } + +if (max_hwseg >= display->controller->max_segments) { +dev_err (dev,"segment %u exceeds controller max_segments %u\n" , + max_hwseg, display->controller->max_segments); +return -EINVAL ; + } + + display->num_hwgrid = max_hwgrid +1 ; + display->num_hwseg = max_hwseg +1 ; + +return 0 ; +}...
Quoted 9 lines
Quoted 6 lines
+/**
+ *tm16xx_probe()- Probe and initialize display device, register LEDs
+ * @display: pointer totm16xx_display
+ *
+ * Return: 0 on success, negative error code on failure
+ */Unneeded kernel-doc.
Will remove kernel-doc.
Quoted 8 lines
drivers/auxdisplay/tm16xx_core.c line 335
Quoted 5 lines
drivers/auxdisplay/tm16xx_core.c new file +5
-0+int tm16xx_probe (struct tm16xx_display *display) +{ +struct device *dev = display->dev; +struct led_classdev *main = &display->main_led; +struct led_init_data led_init = {0 };'0' is not needed.
Will use empty braces:
struct led_init_data led_init = {};
Quoted 11 lines
Quoted 11 lines
drivers/auxdisplay/tm16xx_core.c new file +11
-0+struct fwnode_handle *leds_node; +struct tm16xx_led *led; +unsigned int nbits, i; +int ret; + + ret =tm16xx_parse_fwnode (dev, display); +if (ret) +return dev_err_probe (dev, ret,"Failed to parse device tree\n" ); + + nbits =tm16xx_led_nbits (display); + display->state =devm_bitmap_zalloc (dev, nbits,GFP_KERNEL );
Quoted 9 lines
drivers/auxdisplay/tm16xx_core.c line 352
Quoted 6 lines
drivers/auxdisplay/tm16xx_core.c new file +6
-0+if (!display->state) +return -ENOMEM ; + + ret =devm_mutex_init (display->dev, &display->lock); +if (ret) +return dev_err_probe (dev, ret,"Failed to initialize mutex\n" );I believe it's ENOMEM here, so we don't need an error message.
You are right, underlaying __devm_add_action() only returns -ENOMEM. Will remove this dev_err_probe().
Quoted 5 lines
drivers/auxdisplay/tm16xx_core.c line 355
Quoted 2 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+INIT_WORK (&display->flush_init, tm16xx_display_flush_init); +INIT_WORK (&display->flush_display, tm16xx_display_flush_data);
devm-helpers.hhave something for this case, I believe.
Cannot use devm_work_autocancel(). The shutdown sequence requires specific
ordering: (1) unregister LEDs to stop triggers, (2) clear display state, (3) flush pending work, (4) turn off display. This sequence prevents hardware access races when triggers attempt to update the display during removal. Manual INIT_WORK with explicit flush/cancel in remove() provides this control.
Quoted 6 lines
drivers/auxdisplay/tm16xx_core.c line 358
Quoted 2 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+/* Initialize main LED properties */ + led_init.fwnode =dev_fwnode (dev);/* apply label property */ I didn't get a comment. This not only about label, but for entire set of properties that led framework can consume.
Will remove /* apply label property */
Quoted 8 lines
drivers/auxdisplay/tm16xx_core.c line 362
Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c new file +4
-0+ main->max_brightness = display->controller->max_brightness; +device_property_read_u32 (dev,"max-brightness" , &main->max_brightness); + main->max_brightness =umin (main->max_brightness, + display->controller->max_brightness);Hmm... Why 'u' variant of macro?
Quoted 6 lines
drivers/auxdisplay/tm16xx_core.c line 366
Quoted 3 lines
drivers/auxdisplay/tm16xx_core.c new file +3
-0+ main->brightness = main->max_brightness; +device_property_read_u32 (dev,"default-brightness" , &main->brightness); + main->brightness =umin (main->brightness, main->max_brightness);Ditto.
Correct for unsigned brightness values. umin() is the appropriate macro for unsigned types to avoid type conversion warnings.
Quoted 3 lines
Given a comment about propagating fwnode, why do we need all this? Doesn't led core take care of these properties as well?
Manual handling is necessary because:
1. default-brightness: Not implemented in LED core
2. max-brightness defaulting: If DT property is absent, default to controller->max_brightness
3. Ceiling enforcement: When DT property IS present, clamp to not exceed hardware limits (controller->max_brightness)
LED core only reads max-brightness optionally, it doesn't handle defaulting or hardware ceiling enforcement.
Quoted 17 lines
Quoted 16 lines
drivers/auxdisplay/tm16xx_core.c new file +16
-0+ main->brightness_set = tm16xx_brightness_set; + main->flags =LED_RETAIN_AT_SHUTDOWN |LED_CORE_SUSPENDRESUME ; + +/* Register individual LEDs from device tree */ + ret =led_classdev_register_ext (dev, main, &led_init); +if (ret) +return dev_err_probe (dev, ret,"Failed to register main LED\n" ); + + i =0 ; + led_init.devicename =dev_name (main->dev); + led_init.devname_mandatory = true; + led_init.default_label ="led" ; + leds_node =device_get_named_child_node (dev,"leds" ); +fwnode_for_each_available_child_node_scoped (leds_node, child) { + led_init.fwnode = child; + led = &display->leds[i];
Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c line 384
Quoted 1 line
drivers/auxdisplay/tm16xx_core.c new file +1
-0+ led->cdev.max_brightness =1 ;That should be set to default by the led core based on the property value, not the case?
Individual icons are hardware-constrained to on/off (max_brightness = 1) regardless of DT properties. This enforces hardware limits, not reads properties.
Quoted 7 lines
drivers/auxdisplay/tm16xx_core.c line 388
Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c new file +4
-0+ led->cdev.brightness_set = tm16xx_led_set; + led->cdev.flags =LED_RETAIN_AT_SHUTDOWN |LED_CORE_SUSPENDRESUME ; + + ret =led_classdev_register_ext (dev, &led->cdev, &led_init);Why not devm_led_*()?
Intentional non-devm design documented in commit notes. Explicit unregistration before removal immediately stops LED triggers, preventing them from accessing hardware post-removal. devm_led_*() would require complex brightness callback state tracking to handle trigger activity during remove(). Explicit unregister is cleaner and eliminates this race.
Quoted 15 lines
Quoted 14 lines
drivers/auxdisplay/tm16xx_core.c new file +14
-0+if (ret) { +dev_err_probe (dev, ret,"Failed to register LED %s\n" , + led->cdev.name); + goto unregister_leds; + } + + i++; + } + + ret =tm16xx_display_init (display); +if (ret) { +dev_err_probe (dev, ret,"Failed to initialize display\n" ); + goto unregister_leds; + }
Quoted 11 lines
drivers/auxdisplay/tm16xx_core.c line 409
Quoted 6 lines
drivers/auxdisplay/tm16xx_core.c new file +6
-0+ ret =linedisp_attach (&display->linedisp, display->main_led.dev, + display->num_digits, &tm16xx_linedisp_ops); +if (ret) { +dev_err_probe (dev, ret,"Failed to initialize line-display\n" ); + goto unregister_leds; + }If we haven't yet devm for this, it can be
1) introduced, OR
2) wrapped to become a such (seedevm_add_action_or_reset()usage).
While devm_add_action_or_reset() could wrap linedisp_detach(), the overall shutdown still requires explicit ordering across multiple subsystems (linedisp, LEDs, workqueues, hardware). Using devm for just one component while manually managing others adds complexity without benefit. The current explicit approach keeps all cleanup logic together in remove() for clarity.
Quoted 4 lines
Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c new file +4
-0+return 0 ; + +unregister_leds: +while (i--)
Quoted 9 lines
drivers/auxdisplay/tm16xx_core.c line 420
Quoted 6 lines
drivers/auxdisplay/tm16xx_core.c new file +6
-0+led_classdev_unregister (&display->leds[i].cdev); + +led_classdev_unregister (main); +return ret; +} +EXPORT_SYMBOL_NS (tm16xx_probe,"TM16XX" );Needs to be namespaced
_GPLvariant. Same for all exports.
Will change all exports toEXPORT_SYMBOL_NS_GPL(symbol, "TM16XX").
Quoted 7 lines
Quoted 4 lines
+/**
+ *tm16xx_remove()- Remove display, unregister LEDs, blank output
+ * @display: pointer totm16xx_display
+ */Unneeded kernel-doc.
Will remove kernel-doc.
Quoted 7 lines
Quoted 6 lines
drivers/auxdisplay/tm16xx_core.c new file +6
-0+void tm16xx_remove (struct tm16xx_display *display) +{ +unsigned int nbits =tm16xx_led_nbits (display); +struct tm16xx_led *led; + +linedisp_detach (display->main_led.dev);
Quoted 9 lines
drivers/auxdisplay/tm16xx_core.c line 437
Quoted 5 lines
drivers/auxdisplay/tm16xx_core.c new file +5
-0+/* +* Unregister LEDs first to immediately stop trigger activity. +* This prevents LED triggers from attempting to access hardware +* after it's been disconnected or driver unloaded. +*/ After switching to devm_*() this comment won't be needed (besides that it will come orphaned).
Should not switch to devm_*() as explained above.
Quoted 11 lines
Quoted 11 lines
drivers/auxdisplay/tm16xx_core.c new file +11
-0+for (int i =0 ; i < display->num_leds; i++) { + led = &display->leds[i]; +led_classdev_unregister (&led->cdev); + } +led_classdev_unregister (&display->main_led); + +/* Clear display state */ +bitmap_zero (display->state, nbits); +schedule_work (&display->flush_display); +flush_work (&display->flush_display); +
Quoted 9 lines
drivers/auxdisplay/tm16xx_core.c line 454
Quoted 6 lines
drivers/auxdisplay/tm16xx_core.c new file +6
-0+/* Turn off display */ + display->main_led.brightness =LED_OFF ; +schedule_work (&display->flush_init); +flush_work (&display->flush_init); +} +EXPORT_SYMBOL_NS (tm16xx_remove,"TM16XX" );
_GPL
Will change all exports toEXPORT_SYMBOL_NS_GPL(symbol, "TM16XX").
Best Regards,
Jean-François Lessard
Hi Andy,
Thanks for your feedback.
Quoted 2 lines · Jean-François Lessard
Quoted 1 line · Andy Shevchenko
On Fri, Sep 26, 2025 at 10:19:05AM -0400, Jean-François Lessard wrote:
...
Quoted 7 lines
Quoted 6 lines
drivers/auxdisplay/tm16xx_core.c line 74
Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c new file +4
-0+static inline void tm16xx_set_seg (const struct tm16xx_display *display, +const u8 hwgrid,const u8 hwseg,const bool on) +{ +assign_bit (hwgrid * display->num_hwseg + hwseg, display->state, on);Do you need an atomic call here? Perhaps
__assign_bit()would suffice,
Quoted 8 lines
Keeping
assign_bit(), it's required here. Two distinct concurrency scenarios exist:
- Bitmap: Multiple LED triggers (network, timer) + userspace write todisplay->stateconcurrently -> need atomic ops
- Hardware: Mutex serializes different hardware operations (flush_init,flush_display, keypad polling) that can race
The mutex doesn't eliminate bitmap concurrency needs, they're orthogonal concerns.
Okay, but the below bitmap_read() is non-atomic. And in general the bitmap API is not atomic.
Quoted 1 line
Quoted 1 line
Quoted 1 line
+}
...
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
drivers/auxdisplay/tm16xx_core.c new file +5
-0+ ret =fwnode_property_read_u32_array (child, +"segments" , segments, +TM16XX_DIGIT_SEGMENTS *2 ); +if (ret <0 ) +return ret;
Quoted 7 lines
Quoted 2 lines
Why '< 0'? Here it's definitely not a counting call, so it should never return positive in this case.
Keeping if (ret < 0). While usage with non-NULL buffer won't return positive values,
fwnode_property_read_u32_array()documentation explicitly states it can return count when buffer is NULL. Using < 0 is the defensive, API-compliant pattern that matches the function signature.
Okay, it's fine to keep this way.
...
Quoted 9 lines
Quoted 5 lines
drivers/auxdisplay/tm16xx_core.c line 295
Quoted 2 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+ ret =fwnode_property_read_u32_array (child,"reg" , reg,2 ); +if (ret <0 )Ditto,.
As per above.
Quoted 1 line
Quoted 1 line
+ return ret;
...
Quoted 10 lines
Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c line 355
Quoted 2 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+INIT_WORK (&display->flush_init, tm16xx_display_flush_init); +INIT_WORK (&display->flush_display, tm16xx_display_flush_data);
devm-helpers.hhave something for this case, I believe.Cannot use
devm_work_autocancel(). The shutdown sequence requires specific
ordering: (1) unregister LEDs to stop triggers, (2) clear display state, (3) flush pending work, (4) turn off display. This sequence prevents hardware access races when triggers attempt to update the display during removal. ManualINIT_WORKwith explicit flush/cancel inremove()provides this control.
Do you mean that the removal order is not symmetrical to the probe one? At bare minimum this needs a comment in the code (as summary above) to explain why devm_*() are not being used.
...
Quoted 7 lines
Quoted 7 lines
drivers/auxdisplay/tm16xx_core.c line 362
Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c new file +4
-0+ main->max_brightness = display->controller->max_brightness; +device_property_read_u32 (dev,"max-brightness" , &main->max_brightness); + main->max_brightness =umin (main->max_brightness, + display->controller->max_brightness);Hmm... Why 'u' variant of macro?
Quoted 8 lines
Quoted 5 lines
drivers/auxdisplay/tm16xx_core.c line 366
Quoted 3 lines
drivers/auxdisplay/tm16xx_core.c new file +3
-0+ main->brightness = main->max_brightness; +device_property_read_u32 (dev,"default-brightness" , &main->brightness); + main->brightness =umin (main->brightness, main->max_brightness);Ditto.
Correct for unsigned brightness values.
umin()is the appropriate macro for unsigned types to avoid type conversion warnings.
But are you in control of all the variable types? If so, why not align the types?
...
Quoted 5 lines
Quoted 2 lines
Given a comment about propagating fwnode, why do we need all this? Doesn't led core take care of these properties as well?
Manual handling is necessary because:
1. default-brightness: Not implemented in LED core
Oh, indeed, I mixed this with default-state. But the side question here is what prevents us from implementing it? I suspect there were discussions in the past, but I haven;t dug the lore archive to see if any indeed happened.
Quoted 7 lines
2. max-brightness defaulting: If DT property is absent, default to
controller->max_brightness
3. Ceiling enforcement: When DT property IS present, clamp to not exceed hardware limits (controller->max_brightness)LED core only reads max-brightness optionally, it doesn't handle defaulting or hardware ceiling enforcement.
Yep, thanks for elaborating.
...
Quoted 9 lines
Quoted 3 lines
Quoted 1 line
+ ret =
led_classdev_register_ext(dev, &led->cdev, &led_init);Why not devm_led_*()?
Intentional non-devm design documented in commit notes. Explicit unregistration before removal immediately stops LED triggers, preventing them from accessing hardware post-removal. devm_led_*() would require complex brightness callback state tracking to handle trigger activity during
remove(). Explicit unregister is cleaner and eliminates this race.
Right, so I think the summary of this needs to be commented on in the code (as well).
...
Quoted 8 lines
Quoted 7 lines
drivers/auxdisplay/tm16xx_core.c line 405
Quoted 2 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+ ret =linedisp_attach (&display->linedisp, display->main_led.dev, + display->num_digits, &tm16xx_linedisp_ops);If we haven't yet devm for this, it can be
1) introduced, OR
2) wrapped to become a such (seedevm_add_action_or_reset()usage).
Quoted 5 lines
While
devm_add_action_or_reset()could wraplinedisp_detach(), the overall shutdown still requires explicit ordering across multiple subsystems (linedisp, LEDs, workqueues, hardware). Using devm for just one component while manually managing others adds complexity without benefit. The current explicit approach keeps all cleanup logic together inremove()for clarity.
Okay, I need to have a look at this again when you send a new version, but I want to finish reviewing this one. Sorry it takes time.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Le 1 novembre 2025 13 h 06 min 55 s HAE, Andy Shevchenko <[email protected]> a écrit :
Quoted 23 lines
Quoted 2 lines · Jean-François Lessard
Quoted 1 line · Andy Shevchenko
On Fri, Sep 26, 2025 at 10:19:05AM -0400, Jean-François Lessard wrote:
...
Quoted 7 lines
Quoted 6 lines
drivers/auxdisplay/tm16xx_core.c line 74
Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c new file +4
-0+static inline void tm16xx_set_seg (const struct tm16xx_display *display, +const u8 hwgrid,const u8 hwseg,const bool on) +{ +assign_bit (hwgrid * display->num_hwseg + hwseg, display->state, on);Do you need an atomic call here? Perhaps
__assign_bit()would suffice,Quoted 8 lines
Keeping
assign_bit(), it's required here. Two distinct concurrency scenarios exist:
- Bitmap: Multiple LED triggers (network, timer) + userspace write todisplay->stateconcurrently -> need atomic ops
- Hardware: Mutex serializes different hardware operations (flush_init,flush_display, keypad polling) that can race
The mutex doesn't eliminate bitmap concurrency needs, they're orthogonal concerns.
Quoted 3 lines
Okay, but the below
bitmap_read()is non-atomic. And in general the bitmap API is not atomic.
The atomic assign_bit() protects read-modify-write operations from concurrent modifications. Reads are non-critical since every write schedules a flush work, providing eventual consistency. This is a valid optimization pattern and doesn't
require atomic reads.
Quoted 14 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
+}
...
Quoted 10 lines
Quoted 9 lines
drivers/auxdisplay/tm16xx_core.c line 267
Quoted 6 lines
drivers/auxdisplay/tm16xx_core.c new file +5
-0+ ret =fwnode_property_read_u32_array (child, +"segments" , segments, +TM16XX_DIGIT_SEGMENTS *2 ); +if (ret <0 ) +return ret;Why '< 0'? Here it's definitely not a counting call, so it should never return positive in this case.
Quoted 7 lines
Quoted 4 lines
Keeping if (ret < 0). While usage with non-NULL buffer won't return positive values,
fwnode_property_read_u32_array()documentation explicitly states it can return count when buffer is NULL. Using < 0 is the defensive, API-compliant pattern that matches the function signature.Okay, it's fine to keep this way.
Acknowledged.
Quoted 25 lines
...
Quoted 9 lines
Quoted 5 lines
drivers/auxdisplay/tm16xx_core.c line 295
Quoted 2 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+ ret =fwnode_property_read_u32_array (child,"reg" , reg,2 ); +if (ret <0 )Ditto,.
As per above.
Quoted 1 line
Quoted 1 line
+ return ret;
...
Quoted 10 lines
Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c line 355
Quoted 2 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+INIT_WORK (&display->flush_init, tm16xx_display_flush_init); +INIT_WORK (&display->flush_display, tm16xx_display_flush_data);
devm-helpers.hhave something for this case, I believe.Cannot use
devm_work_autocancel(). The shutdown sequence requires specific
ordering: (1) unregister LEDs to stop triggers, (2) clear display state, (3) flush pending work, (4) turn off display. This sequence prevents hardware access races when triggers attempt to update the display during removal. ManualINIT_WORKwith explicit flush/cancel inremove()provides this control.
Quoted 4 lines
Do you mean that the removal order is not symmetrical to the probe one? At bare minimum this needs a comment in the code (as summary above) to explain why devm_*() are not being used.
Acknowledged. I'll add a code comment summarizing the non-devm rationale for both work queues and LED registration: explicit sequencing prevents LED triggers from accessing hardware post-removal.
Quoted 13 lines
...
Quoted 11 lines
Quoted 11 lines
drivers/auxdisplay/tm16xx_core.c line 362
Quoted 4 lines
drivers/auxdisplay/tm16xx_core.c new file +4
-0+ main->max_brightness = display->controller->max_brightness; +device_property_read_u32 (dev,"max-brightness" , &main->max_brightness); + main->max_brightness =umin (main->max_brightness, + display->controller->max_brightness);Hmm... Why 'u' variant of macro?
Quoted 3 lines
drivers/auxdisplay/tm16xx_core.c new file +3
-0+ main->brightness = main->max_brightness; +device_property_read_u32 (dev,"default-brightness" , &main->brightness); + main->brightness =umin (main->brightness, main->max_brightness);
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Ditto.
Correct for unsigned brightness values.
umin()is the appropriate macro for unsigned types to avoid type conversion warnings.But are you in control of all the variable types? If so, why not align the types?
brightness and max_brightness are u32 (unsigned). Using umin() is the appropriate macro for unsigned comparisons. If type definitions change in the future, the compiler will flag any incompatibilities.
I think the overall design is now pretty sound. I would like to get sure we are not gold-plating and that we stay focused on actual issues.
Quoted 5 lines
...
Quoted 3 lines
Quoted 2 lines
Given a comment about propagating fwnode, why do we need all this? Doesn't led core take care of these properties as well?
Quoted 8 lines
Quoted 2 lines
Manual handling is necessary because:
1. default-brightness: Not implemented in LED coreOh, indeed, I mixed this with default-state. But the side question here is what prevents us from implementing it? I suspect there were discussions in the past, but I haven;t dug the lore archive to see if any indeed happened.
default-brightness could be added to LED core as a separate enhancement. For this TM16xx driver, manual handling is necessary given the same considerations as max-brightness. Any future LED core changes can be addressed independently.
Quoted 10 lines
Quoted 7 lines
2. max-brightness defaulting: If DT property is absent, default to
controller->max_brightness
3. Ceiling enforcement: When DT property IS present, clamp to not exceed hardware limits (controller->max_brightness)LED core only reads max-brightness optionally, it doesn't handle defaulting or hardware ceiling enforcement.
Yep, thanks for elaborating.
I'll add a code comment about defaulting and hardware ceiling enforcement.
Quoted 6 lines
...
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
+ ret =
led_classdev_register_ext(dev, &led->cdev, &led_init);Why not devm_led_*()?
Quoted 9 lines
Quoted 5 lines
Intentional non-devm design documented in commit notes. Explicit unregistration before removal immediately stops LED triggers, preventing them from accessing hardware post-removal. devm_led_*() would require complex brightness callback state tracking to handle trigger activity during
remove(). Explicit unregister is cleaner and eliminates this race.Right, so I think the summary of this needs to be commented on in the code (as well).
I'll add code comment explaining the non-devm rationale for LED registration.
Quoted 10 lines
...
Quoted 8 lines
Quoted 7 lines
drivers/auxdisplay/tm16xx_core.c line 405
Quoted 2 lines
drivers/auxdisplay/tm16xx_core.c new file +2
-0+ ret =linedisp_attach (&display->linedisp, display->main_led.dev, + display->num_digits, &tm16xx_linedisp_ops);If we haven't yet devm for this, it can be
1) introduced, OR
2) wrapped to become a such (seedevm_add_action_or_reset()usage).
Quoted 9 lines
Quoted 5 lines
While
devm_add_action_or_reset()could wraplinedisp_detach(), the overall shutdown still requires explicit ordering across multiple subsystems (linedisp, LEDs, workqueues, hardware). Using devm for just one component while manually managing others adds complexity without benefit. The current explicit approach keeps all cleanup logic together inremove()for clarity.Okay, I need to have a look at this again when you send a new version, but I want to finish reviewing this one. Sorry it takes time.
Thanks for the thorough review of the core driver patch. Before I finalize v6 with these changes and added code comments, would you be able to review the remaining patches in the series (keypad/I2C/SPI bus support)? Comprehensive feedback now will help ensure v6 addresses all architectural concerns systematically, rather than discovering issues after resubmission.
Thanks,
Jean-François
PATCH v5 5/7 auxdisplay: TM16xx: Add keypad support for scanning matrix keys
In reply to Jean-François LessardAdd support for keypad scanning on TM16xx-compatible auxiliary display controllers. It handles keypad initialization, scanning, and input reporting for matrix keys managed by the TM16xx devices.
Key features include:
- Input device registration configured by device properties (poll-interval, linux,keymap, autorepeat)
- Key state tracking using managed bitmaps
- Matrix scanning and event reporting integrated with Linux input subsystem
This code is separated from main core driver to improve maintainability and reviewability.
---
Notes:
checkpatch reports false positives that are intentionally ignored:
COMPLEX_MACRO/MACRO_ARG_REUSE for tm16xx_for_each_key(): This is a standard iterator pattern following kernel conventions (similar to for_each_* macros throughout the kernel). The nested for loops are the correct implementation for matrix iteration.
MAINTAINERS | 1 + drivers/auxdisplay/Kconfig | 9 ++ drivers/auxdisplay/Makefile | 1 + drivers/auxdisplay/tm16xx.h | 25 ++++ drivers/auxdisplay/tm16xx_core.c | 4 + drivers/auxdisplay/tm16xx_keypad.c | 196 +++++++++++++++++++++++++++++ 6 files changed, 236 insertions(+) create mode 100644 drivers/auxdisplay/tm16xx_keypad.c
MAINTAINERS +1 -0
@@ -25448,6 +25448,7 @@ F: Documentation/ABI/testing/sysfs-class-leds-tm16xx F: Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml F: drivers/auxdisplay/tm16xx.h F: drivers/auxdisplay/tm16xx_core.c +F: drivers/auxdisplay/tm16xx_keypad.c TMIO/SDHI MMC DRIVER M: Wolfram Sang <[email protected]>
drivers/auxdisplay/Kconfig +9 -0
@@ -528,13 +528,22 @@ config SEG_LED_GPIO config TM16XX tristate + depends on INPUT + select INPUT_MATRIXKMAP select LEDS_CLASS select LEDS_TRIGGERS select LINEDISP select NEW_LEDS + select TM16XX_KEYPAD if (INPUT) help Core TM16XX-compatible 7-segment LED controllers module +config TM16XX_KEYPAD + bool + depends on TM16XX + help + Enable keyscan support for TM16XX driver. + # # Character LCD with non-conforming interface section #
drivers/auxdisplay/Makefile +1 -0
@@ -18,3 +18,4 @@ obj-$(CONFIG_PARPORT_PANEL) += panel.o obj-$(CONFIG_SEG_LED_GPIO) += seg-led-gpio.o obj-$(CONFIG_TM16XX) += tm16xx.o tm16xx-y += tm16xx_core.o +tm16xx-$(CONFIG_TM16XX_KEYPAD) += tm16xx_keypad.o
drivers/auxdisplay/tm16xx.h +25 -0
@@ -103,6 +103,7 @@struct tm16xx_display ;struct tm16xx_digit ;struct tm16xx_led ; +struct tm16xx_keypad ;/** * DOC: struct tm16xx_controller - Controller-specific operations and limits
@@ -133,6 +134,7 @@ struct tm16xx_controller {* @dev: Pointer to device struct. * @controller: Controller-specific function table and limits. * @linedisp: character line display structure +* @keypad: Opaque pointer to tm16xx_keypad struct. * @spi_buffer: DMA-safe buffer for SPI transactions, or NULL for I2C. * @num_hwgrid: Number of controller grids in use. * @num_hwseg: Number of controller segments in use.
@@ -150,6 +152,7 @@ struct tm16xx_controller {struct tm16xx_display {struct device *dev;const struct tm16xx_controller *controller; +struct tm16xx_keypad *keypad;struct linedisp linedisp;u8 *spi_buffer;u8 num_hwgrid;
@@ -169,4 +172,26 @@ struct tm16xx_display {int tm16xx_probe (struct tm16xx_display *display);void tm16xx_remove (struct tm16xx_display *display); +/* keypad support */ +#if IS_ENABLED (CONFIG_TM16XX_KEYPAD ) +int tm16xx_keypad_probe (struct tm16xx_display *display); +void tm16xx_set_key (const struct tm16xx_display *display,const int row, +const int col,const bool pressed); +#else +static inline int tm16xx_keypad_probe (struct tm16xx_display *display) +{ +return 0 ; +} + +static inline void tm16xx_set_key (const struct tm16xx_display *display, +const int row,const int col, +const bool pressed) +{ +} +#endif + +#define tm16xx_for_each_key (display, _r, _c) \ + for (int _r = 0; _r < (display)->controller->max_key_rows; _r++) \ + for (int _c = 0; _c < (display)->controller->max_key_cols; _c++) +#endif /* _TM16XX_H */
drivers/auxdisplay/tm16xx_core.c +4 -0
@@ -408,6 +408,10 @@ int tm16xx_probe(struct tm16xx_display *display) goto unregister_leds; } + ret =tm16xx_keypad_probe (display); +if (ret) +dev_warn (dev,"Failed to initialize keypad: %d\n" , ret); +return 0 ; unregister_leds:
drivers/auxdisplay/tm16xx_keypad.c new file +196 -0
196 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v5 6/7 auxdisplay: TM16xx: Add support for I2C-based controllers
In reply to Jean-François LessardAdd support for TM16xx-compatible auxiliary display controllers connected via the I2C bus.
The implementation includes:
- I2C driver registration and initialization
- Probe/remove logic for I2C devices
- Controller-specific handling and communication sequences
- Integration with the TM16xx core driver for common functionality
This allows platforms using TM16xx or compatible controllers over I2C to be managed by the TM16xx driver infrastructure.
--- MAINTAINERS | 1 + drivers/auxdisplay/Kconfig | 16 ++ drivers/auxdisplay/Makefile | 1 + drivers/auxdisplay/tm16xx_i2c.c | 332 ++++++++++++++++++++++++++++++++ 4 files changed, 350 insertions(+) create mode 100644 drivers/auxdisplay/tm16xx_i2c.c
MAINTAINERS +1 -0
@@ -25448,6 +25448,7 @@ F: Documentation/ABI/testing/sysfs-class-leds-tm16xx F: Documentation/devicetree/bindings/auxdisplay/titanmec,tm16xx.yaml F: drivers/auxdisplay/tm16xx.h F: drivers/auxdisplay/tm16xx_core.c +F: drivers/auxdisplay/tm16xx_i2c.c F: drivers/auxdisplay/tm16xx_keypad.c TMIO/SDHI MMC DRIVER
drivers/auxdisplay/Kconfig +16 -0
@@ -544,6 +544,22 @@ config TM16XX_KEYPAD help Enable keyscan support for TM16XX driver. +config TM16XX_I2C + tristate "TM16XX-compatible I2C 7-segment LED controllers with keyscan" + depends on I2C + select TM16XX + help + This driver supports the following TM16XX compatible + I2C (2-wire) 7-segment led display chips: + - Titanmec: TM1650 + - Fuda Hisi: FD650, FD655, FD6551 + - i-Core: AiP650 + - Winrise: HBS658 + + To compile this driver as a module, choose M here: the module + will be called tm16xx_i2c and you will also get tm16xx for the + core module. + # # Character LCD with non-conforming interface section #
drivers/auxdisplay/Makefile +1 -0
@@ -19,3 +19,4 @@ obj-$(CONFIG_SEG_LED_GPIO) += seg-led-gpio.o obj-$(CONFIG_TM16XX) += tm16xx.o tm16xx-y += tm16xx_core.o tm16xx-$(CONFIG_TM16XX_KEYPAD) += tm16xx_keypad.o +obj-$(CONFIG_TM16XX_I2C) += tm16xx_i2c.o
drivers/auxdisplay/tm16xx_i2c.c new file +332 -0
332 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v5 6/7] auxdisplay: TM16xx: Add support for I2C-based controllers
Quoted 11 lines · Jean-François Lessard
Add support for TM16xx-compatible auxiliary display controllers connected via the I2C bus.
The implementation includes:
- I2C driver registration and initialization
- Probe/remove logic for I2C devices
- Controller-specific handling and communication sequences
- Integration with the TM16xx core driver for common functionalityThis allows platforms using TM16xx or compatible controllers over I2C to be managed by the TM16xx driver infrastructure.
...
drivers/auxdisplay/Kconfig config TM16XX_KEYPAD · line 553
Quoted 3 lines
drivers/auxdisplay/Kconfig +3
-0+ help + This driver supports the following TM16XX compatible + I2C (2-wire) 7-segment led display chips:
LED
drivers/auxdisplay/Kconfig config TM16XX_KEYPAD · line 561
Quoted 8 lines
drivers/auxdisplay/Kconfig +8
-0+ - Titanmec: TM1650 + - Fuda Hisi: FD650, FD655, FD6551 + - i-Core: AiP650 + - Winrise: HBS658 + + To compile this driver as a module, choose M here: the module + will be called tm16xx_i2c and you will also get tm16xx for the + core module.
...
Please, check the include blocks to follow IWYU principle.
+ array_size.h
drivers/auxdisplay/tm16xx_i2c.c line 10
Quoted 2 lines
drivers/auxdisplay/tm16xx_i2c.c new file +2
-0+#include <linux/bitfield.h> +#include <linux/device.h>
dev_printk.hdevice/devres.h
?
+ err
drivers/auxdisplay/tm16xx_i2c.c line 13
Quoted 3 lines
drivers/auxdisplay/tm16xx_i2c.c new file +3
-0+#include <linux/i2c.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h>
+ types.h
...
Quoted 14 lines
drivers/auxdisplay/tm16xx_i2c.c new file +14
-0+static int tm16xx_i2c_probe (struct i2c_client *client) +{ +const struct tm16xx_controller *controller; +struct tm16xx_display *display; +int ret; + + controller =i2c_get_match_data (client); +if (!controller) +return -EINVAL ; + + display =devm_kzalloc (&client->dev,sizeof (*display),GFP_KERNEL ); +if (!display) +return -ENOMEM ; +
drivers/auxdisplay/tm16xx_i2c.c line 40
Quoted 10 lines
drivers/auxdisplay/tm16xx_i2c.c new file +9
-0+ display->dev = &client->dev; + display->controller = controller; + +i2c_set_clientdata (client, display); + ret =tm16xx_probe (display); +if (ret) +return ret; + +return 0 ;
return tm16xx_probe(...);
Quoted 1 line
+}
...
drivers/auxdisplay/tm16xx_i2c.c line 48
Quoted 6 lines
drivers/auxdisplay/tm16xx_i2c.c new file +6
-0+static void tm16xx_i2c_remove (struct i2c_client *client) +{ +struct tm16xx_display *display =i2c_get_clientdata (client); + +tm16xx_remove (display); +}
Just provide dem_tm16xx_probe() and drop this.
...
drivers/auxdisplay/tm16xx_i2c.c line 92
Quoted 6 lines
drivers/auxdisplay/tm16xx_i2c.c new file +6
-0+static int tm16xx_i2c_read (struct tm16xx_display *display,u8 cmd,u8 *data,size_t len) +{ +struct i2c_client *i2c =to_i2c_client (display->dev); + +/* expected sequence: S Command [A] [Data] [A] P */ +struct i2c_msg msgs[1 ] = {{
Why an array out of a sudden? Previous function coped with just a single structure.
Quoted 13 lines
drivers/auxdisplay/tm16xx_i2c.c new file +13
-0+ .addr = cmd >> 1, + .flags = I2C_M_RD | I2C_M_NO_RD_ACK, + .len = len, + .buf = data, + }}; +int ret; + + ret =i2c_transfer (i2c->adapter, msgs,ARRAY_SIZE (msgs)); +if (ret <0 ) +return ret; + +return (ret ==ARRAY_SIZE (msgs)) ?0 : -EIO ; +}
...
drivers/auxdisplay/tm16xx_i2c.c line 117
Quoted 10 lines
drivers/auxdisplay/tm16xx_i2c.c new file +10
-0+static int tm1650_init (struct tm16xx_display *display) +{ +const enum led_brightness brightness = display->main_led.brightness; +u8 cmds[2 ]; + + cmds[0 ] =TM1650_CMD_CTRL ; + cmds[1 ] =TM16XX_CTRL_BRIGHTNESS (brightness, brightness,TM1650 ) | +TM1650_CTRL_SEG8_MODE ; + +return tm16xx_i2c_write (display, cmds,ARRAY_SIZE (cmds));
For cases of char / u8 the sizeof() is fine.
drivers/auxdisplay/tm16xx_i2c.c line 128
Quoted 11 lines
drivers/auxdisplay/tm16xx_i2c.c new file +11
-0+} + +static int tm1650_data (struct tm16xx_display *display,u8 index, +unsigned int grid) +{ +u8 cmds[2 ]; + + cmds[0 ] =TM1650_CMD_ADDR + index *2 ; + cmds[1 ] = grid;/* SEG 1 to 8 */ + +return tm16xx_i2c_write (display, cmds,ARRAY_SIZE (cmds));
Ditto.
Quoted 1 line
+}
...
drivers/auxdisplay/tm16xx_i2c.c line 195
Quoted 5 lines
drivers/auxdisplay/tm16xx_i2c.c new file +5
-0+static void hbs658_swap_nibbles (u8 *data,size_t len) +{ +for (size_t i =0 ; i < len; i++) + data[i] = (data[i] <<4 ) | (data[i] >>4 ); +}
At least these ones
drivers/iio/adc/mcp320x.c:158: *val = (adc->rx_buf[0] << 4 | adc->rx_buf[1] >> 4); drivers/mtd/tests/nandbiterrs.c:83: c = (c & 0x0F) << 4 | (c & 0xF0) >> 4; drivers/usb/atm/ueagle-atm.c:2072: sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
use the same code (and I believe more, but that needs a bit more sophisticated grep).
Perhaps make it a part of include/linux/swab.h
as
static inline void swab_nibbles(u8 *buf, unsigned int words)
{
...
}in a separate patch?
...
Quoted 13 lines
drivers/auxdisplay/tm16xx_i2c.c new file +13
-0+static int hbs658_init (struct tm16xx_display *display) +{ +const enum led_brightness brightness = display->main_led.brightness; +u8 cmd; +int ret; + +/* Set data command */ + cmd =TM16XX_CMD_WRITE |TM16XX_DATA_ADDR_AUTO ; +hbs658_swap_nibbles (&cmd,1 ); + ret =tm16xx_i2c_write (display, &cmd,1 ); +if (ret) +return ret; +
drivers/auxdisplay/tm16xx_i2c.c line 218
Quoted 10 lines
drivers/auxdisplay/tm16xx_i2c.c new file +9
-0+/* Set control command with brightness */ + cmd =TM16XX_CMD_CTRL | +TM16XX_CTRL_BRIGHTNESS (brightness, brightness -1 ,TM16XX ); +hbs658_swap_nibbles (&cmd,1 ); + ret =tm16xx_i2c_write (display, &cmd,1 ); +if (ret) +return ret; + +return 0 ;
return tm16xx_i2c_write(display, &cmd, 1);
Quoted 1 line
+}
...
drivers/auxdisplay/tm16xx_i2c.c line 247
Quoted 1 line
drivers/auxdisplay/tm16xx_i2c.c new file +1
-0+if (keycode !=0xFF ) {
Hmm... Maybe
if (keycode == 0xFF) return 0;
?
Also you use 0xFF magic several times. If it's the same semantically, define it with name and use everywhere, if it's different we need either comments or a few definitions for each semantically different case.
Quoted 5 lines
drivers/auxdisplay/tm16xx_i2c.c new file +5
-0+ col =FIELD_GET (HBS658_KEY_COL_MASK , keycode); +tm16xx_set_key (display,0 , col, true); + } + +return 0 ;
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v5 7/7 auxdisplay: TM16xx: Add support for SPI-based controllers
In reply to Jean-François LessardAdd support for TM16xx-compatible auxiliary display controllers connected via the SPI bus.
The implementation includes:
- SPI driver registration and initialization
- Probe/remove logic for SPI devices
- Controller-specific handling and communication sequences
- Integration with the TM16xx core driver for common functionality
This allows platforms using TM16xx or compatible controllers over SPI to be managed by the TM16xx driver infrastructure.
--- MAINTAINERS | 1 + drivers/auxdisplay/Kconfig | 16 ++ drivers/auxdisplay/Makefile | 1 + drivers/auxdisplay/tm16xx_spi.c | 397 ++++++++++++++++++++++++++++++++ 4 files changed, 415 insertions(+) create mode 100644 drivers/auxdisplay/tm16xx_spi.c
MAINTAINERS +1 -0
@@ -25450,6 +25450,7 @@ F: drivers/auxdisplay/tm16xx.h F: drivers/auxdisplay/tm16xx_core.c F: drivers/auxdisplay/tm16xx_i2c.c F: drivers/auxdisplay/tm16xx_keypad.c +F: drivers/auxdisplay/tm16xx_spi.c TMIO/SDHI MMC DRIVER M: Wolfram Sang <[email protected]>
drivers/auxdisplay/Kconfig +16 -0
@@ -560,6 +560,22 @@ config TM16XX_I2C will be called tm16xx_i2c and you will also get tm16xx for the core module. +config TM16XX_SPI + tristate "TM16XX-compatible SPI 7-segment LED controllers with keyscan" + depends on SPI + select TM16XX + help + This driver supports the following TM16XX compatible + SPI (3-wire) 7-segment led display chips: + - Titanmec: TM1618, TM1620, TM1628, TM1638 + - Fuda Hisi: FD620, FD628 + - i-Core: AiP1618, AiP1628 + - Princeton: PT6964 + + To compile this driver as a module, choose M here: the module + will be called tm16xx_spi and you will also get tm16xx for the + core module. + # # Character LCD with non-conforming interface section #
drivers/auxdisplay/Makefile +1 -0
@@ -20,3 +20,4 @@ obj-$(CONFIG_TM16XX) += tm16xx.o tm16xx-y += tm16xx_core.o tm16xx-$(CONFIG_TM16XX_KEYPAD) += tm16xx_keypad.o obj-$(CONFIG_TM16XX_I2C) += tm16xx_i2c.o +obj-$(CONFIG_TM16XX_SPI) += tm16xx_spi.o
drivers/auxdisplay/tm16xx_spi.c new file +397 -0
397 lines not on this page · raw message
Signature · 1 line
2.43.0