Add support for CH1115 Controller
Subsystems (3)
v6 cover Add support for CH1115 Controller
This series add support for the CH1115 Controller [1]. It is a monochrome dot matrix OLED controller that supports several interfaces such as SPI and I2C.
This driver only supports the I2C interface, but all common parts could easily be put into a common file to be used with other interfaces. I only have I2C to test with.
This is the first driver I write. The work is based on the driver located at:
- drivers/gpu/drm/sitronix/st7571-i2c.c
- drivers/gpu/drm/sitronix/st7571.c
Tested with Raspberry Pi 3b+ on Linux 7.4-rc1.
Changelog:
v6:
General:
- Patch series based on 7.4-rc1
Driver:
- Fixed KConfig dependencies: added depends on MMU because of DRM_GEM_SHMEM_HELPER select
- Removed unused constant CH1115_MAX_PAGES.
- Removed unused ch1115 struct member pages.
- Fixed width and height checks error messages
- drm connector: use atomic_create_state and remove drm_atomic_helper_connector_reset: This change is because of [3]
- drm CRTC: use drm_atomic_helper_crtc_create_state and remove drm_atomic_helper_crtc_reset. This change is the because of [5] [6]
[7] [8]
- Replaced devm_regmap_init(...) with devm_regmap_init_i2c(...). Deleted related unused code. In this driver I2C_M_IGNORE_NAK is not used.
The way of communicating was carried from an old version of st7571 driver (and me not understanding better). This change is because of [4].
- Early exit on failure in ch1115_encoder_atomic_enable
- Removed "CH1115_CMD_ALL_ON" in shutdown sequence. This was a misunderstanding of what this command did.
- Fixed Sashiko report from v5: "[High] core: uninitialized variable
bl used in IS_ERR check". Apologies for this, my LSP did not highlight the problem and I overlooked it.
- Fixed Sashiko report from v5: "[High] drm: out-of-bounds heap read in ch1115_transform_xy()".
- Fixed Sashiko report from v5: "[Medium] sysfs: unprotected state modification on registered I2C device"
Dt-binding:
- Removed adding Chipwealth to vendor-prefixes.yml. This was added in commit 058ee00216a1 ("dt-bindings: vendor-prefixes: Add Chip Wealth Technology")
Link to v5: https://lore.kernel.org/all/[email protected]/
Note: Sashiko keeps complaining that i2c transfers are called in atomic_update callback stating that it is forbidden to call sleeping functions there because we are in an atomic context. AFAIK this atomic context is not that the kernel is in a non-sleepable state, but refers to the DRM way of working by doing check -> commit. In fact, the driver I based this driver (st7571 [9] -> [10]) and others (ssd103x) do i2c transfer in an atomic plane update. Am I missing something?
v5:
General:
- Patch series based on 7.3-rc1
Driver:
- Fixed KConfig dependencies (OF and BACKLIGHT_CLASS_DEVICE)
- Initializing baclight with backlight_properties struct
- Moved driver from drivers/gpu/drm/chipwealth to drivers/gpu/drm/tiny
- Fixed allocation for hwbuf if width or height are not multiple of 8.
I was allocating less memory than needed in those cases.
- Fixed damage rect horizontal alignment.
Link to v4: https://lore.kernel.org/all/[email protected]/
Note: The last two fixes listed were pointed out by Sashiko in some occasions but when I checked them I dismissed them for false positives because I misunderstood them.
v4:
General:
- Patch series based in kernel v7.3-rc1
Driver:
- Fixed nits found by Christophe JAILLET.
- Fixed max_width and max_height in modeset to avoid having bigger framebuffers than resolution.
Link to v3: https://lore.kernel.org/all/[email protected]/
v3:
- General:
- Patch series based in kernel v7.2
- In dt-bindings:
- Removed "chipwealth,contrast" property (added backlight_device support in driver's code)
- Renamed "chipwealth,invert" -> "chipwealth,inverted"
- Added default value to "chipwealth,offset"
- Removed 'status = "okay"' from example
- Indented example with 4 spaces as stated in the documentation [2]
- In driver code:
- Added support for backlight_device
- Replaced drm_dev_unregister with drm_dev_unplug to cover the dt overlay unload case
- Executing drm shutdown operations before turning off the display
- Checking that the width (panel-timing.hactive) and height (panel-timing.vactive) parameters are greater than 0
Link to v2: https://lore.kernel.org/all/[email protected]/
v2:
- General:
- Patch series based in kernel v7.2
- In dt-bindings:
- Fixed linter problems
- Replaced first_page property with offset
- In driver code:
- Fixed dst_pitch calculation
- Renamed file from ch1115.c to ch1115-i2c.c
- Support flip-vertical and flip-horizontal dt properties
- Fixed several things found by sashiko-ai
Link to v1: https://lore.kernel.org/all/[email protected]/
[1] https://datasheet4u.com/download/1576606/CH1115.html
[2] https://docs.kernel.org/devicetree/bindings/writing-schema.html#annotated-example-schema
[3] https://lore.kernel.org/dri-devel/20261022-drm-no-more-connector-reset-v2-26-0b7e4e85b1e8@kernel.org/
[4] https://lore.kernel.org/dri-devel/[email protected]/
[5] https://lore.kernel.org/all/[email protected]/
[6] https://lore.kernel.org/all/[email protected]/
[7] https://lore.kernel.org/all/[email protected]/
[8] https://lore.kernel.org/all/[email protected]/
[9] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/sitronix/st7571.c#n371
[10] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/sitronix/st7571.c#n224
Nicolás Antinori (3):
dt-bindings: display: add Chipwealth CH1115 OLED Controller drm/ch1115: add support for Chipwealth CH1115 OLED controller
MAINTAINERS: add entry for Chipwealth CH1115 OLED Controller
.../bindings/display/chipwealth,ch1115.yaml | 81 ++ MAINTAINERS | 6 + drivers/gpu/drm/tiny/Kconfig | 17 + drivers/gpu/drm/tiny/Makefile | 1 + drivers/gpu/drm/tiny/ch1115-i2c.c | 859 ++++++++++++++++++ 5 files changed, 964 insertions(+) create mode 100644 Documentation/devicetree/bindings/display/chipwealth,ch1115.yaml create mode 100644 drivers/gpu/drm/tiny/ch1115-i2c.c
--
2.47.3
PATCH v6 1/3 dt-bindings: display: add Chipwealth CH1115 OLED Controller
Chipwealth CH1115 is a controller for monochrome dot matrix OLED panels.
---
Carried "Reviewed-by: Krzysztof Kozlowski <...>" from v3 since the only change was the removal of adding Chipwealth to vendor-prefixes.yml. This was added in commit 058ee00216a1 ("dt-bindings: vendor-prefixes: Add Chip Wealth Technology").
.../bindings/display/chipwealth,ch1115.yaml | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Documentation/devicetree/bindings/display/chipwealth,ch1115.yaml
Documentation/devicetree/bindings/display/chipwealth,ch1115.yaml new file +81 -0
@@ -0,0 +1,81 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/display/chipwealth,ch1115.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Chipwealth CH1115 Display Controller + +maintainers: + - Nicolás Antinori <[email protected]> + +description: + Chipwealth CH1115 is a controller for monochrome dot matrix OLED + panels. + + https://datasheet4u.com/download/1576606/CH1115.html + +allOf: + - $ref: panel/panel-common.yaml# + +properties: + compatible: + const: chipwealth,ch1115 + + reg: + maxItems: 1 + + chipwealth,inverted: + type: boolean + description: + Display pixels are inverted, i.e. 0 is white and 1 is black. + + chipwealth,offset: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 63 + default: 0 + description: + Display start line offset. Specifies the vertical alignment and row shift + along the Y-coordinate. + + width-mm: true + height-mm: true + flip-horizontal: true + flip-vertical: true + panel-timing: true + +required: + - compatible + - reg + - width-mm + - height-mm + - panel-timing + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + display@3c { + compatible = "chipwealth,ch1115"; + reg = <0x3c>; + width-mm = <12>; + height-mm = <8>; + chipwealth,offset = <8>; + panel-timing { + clock-frequency = <0>; + hactive = <88>; + vactive = <48>; + hfront-porch = <0>; + hback-porch = <0>; + hsync-len = <0>; + vsync-len = <0>; + vfront-porch = <0>; + vback-porch = <0>; + }; + }; + };
--
2.47.3
PATCH v6 2/3 drm/ch1115: add support for Chipwealth CH1115 OLED controller
In reply to Nicolás AntinoriChipwealth CH1115 is a controller for monochrome dot matrix OLED panels.
Add DRM support for this chip using i2c bus.
--- drivers/gpu/drm/tiny/Kconfig | 17 + drivers/gpu/drm/tiny/Makefile | 1 + drivers/gpu/drm/tiny/ch1115-i2c.c | 859 ++++++++++++++++++++++++++++++ 3 files changed, 877 insertions(+) create mode 100644 drivers/gpu/drm/tiny/ch1115-i2c.c
drivers/gpu/drm/tiny/Kconfig +17 -0
@@ -36,6 +36,23 @@ config DRM_BOCHS If M is selected the module will be called bochs. +config DRM_CH1115_I2C + tristate "DRM support for CH1115 OLED panels (I2C BUS)" + depends on DRM && MMU && I2C && OF + select BACKLIGHT_CLASS_DEVICE + select DRM_CLIENT_SELECTION + select DRM_GEM_SHMEM_HELPER + select DRM_KMS_HELPER + select REGMAP_I2C + select VIDEOMODE_HELPERS + help + Chipwealth CH1115 is a controller for monochrome dot matrix OLED + panels. + + DRM driver for CH1115 OLED panels connected via I2C. + + If M is selected the module will be called ch1115-i2c. + config DRM_CIRRUS_QEMU tristate "Cirrus driver for QEMU emulated device" depends on DRM && PCI
drivers/gpu/drm/tiny/Makefile +1 -0
@@ -3,6 +3,7 @@ obj-$(CONFIG_DRM_APPLETBDRM) += appletbdrm.o obj-$(CONFIG_DRM_ARCPGU) += arcpgu.o obj-$(CONFIG_DRM_BOCHS) += bochs.o +obj-$(CONFIG_DRM_CH1115_I2C) += ch1115-i2c.o obj-$(CONFIG_DRM_CIRRUS_QEMU) += cirrus-qemu.o obj-$(CONFIG_DRM_GM12U320) += gm12u320.o obj-$(CONFIG_DRM_PANEL_MIPI_DBI) += panel-mipi-dbi.o
drivers/gpu/drm/tiny/ch1115-i2c.c new file +859 -0
859 lines not on this page · raw message
--
2.47.3
PATCH v6 3/3 MAINTAINERS: add entry for Chipwealth CH1115 OLED Controller
In reply to Nicolás AntinoriAdd MAINTAINERS entry for the Chipwealth CH1115 dot matrix OLED controller.
--- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
@@ -8285,6 +8285,12 @@ S: Maintained F: Documentation/devicetree/bindings/display/bridge/chipone,icn6211.yaml F: drivers/gpu/drm/bridge/chipone-icn6211.c +DRM DRIVER FOR CHIPWEALTH CH1115 PANELS +M: Nicolás Antinori <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/display/chipwealth,ch1115.yaml +F: drivers/gpu/drm/tiny/ch1115-i2c.c + DRM DRIVER FOR EBBG FT8719 PANEL M: Joel Selvaraj <[email protected]> S: Maintained
--
2.47.3
[email protected]
AI reviewRe: [PATCH v6 2/3] drm/ch1115: add support for Chipwealth CH1115 OLED controller
In reply to Nicolás AntinoriThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] drm/ch1115: out-of-range display offset 64 sent in ch1115_oled_init() - [Medium] drm/ch1115…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] drm/ch1115: out-of-range display offset 64 sent in ch1115_oled_init()
- [Medium] drm/ch1115: missing DC-DC disable in ch1115_encoder_atomic_disable() --
commit e5268b4f2a7c534421925bdee0145caf63c50632
Author: Nicolás Antinori <[email protected]>
drm/ch1115: add support for Chipwealth CH1115 OLED controller
This commit adds a DRM driver for Chipwealth CH1115 monochrome dot matrix OLED panels connected over I2C.
Quoted 6 lines
drivers/gpu/drm/tiny/ch1115-i2c.c new file +0
-0@@ -0,0 +1,859 @@
[ ... ]
Quoted 6 lines
drivers/gpu/drm/tiny/ch1115-i2c.c new file +6
-0+static int ch1115_oled_init (struct ch1115_device *ch1115) +{ +u8 commands[] = { +CH1115_CMD_OFF , + +CH1115_CMD_CLOCK_DIVIDE_RATIO ,
drivers/gpu/drm/tiny/ch1115-i2c.c line 194
Quoted 10 lines
drivers/gpu/drm/tiny/ch1115-i2c.c new file +10
-0+CH1115_VAL_CLOCK_DIVIDE_RATIO (CH1115_VAL_CLOCK_OSC_FREQ , +CH1115_VAL_CLOCK_DIV_RATIO ), + +CH1115_CMD_MUX_RATIO , + ch1115->height -1 , + +CH1115_CMD_OFFSET , + ch1115->flip_vertical + ? ch1115->y_start_offset + : CH1115_MAX_HEIGHT - ch1115->y_start_offset,
[Severity: Medium]
Does ch1115_oled_init() send an out-of-range value for CH1115_CMD_OFFSET when flip_vertical is false and y_start_offset is 0?
In ch1115_parse_dt(), y_start_offset defaults to 0 when the chipwealth,offset property is omitted, and is otherwise restricted to [0, CH1115_MAX_HEIGHT - 1] (0 to 63):
ret = of_property_read_u32(np, "chipwealth,offset", &val);
if (ret) {
ch1115->y_start_offset = 0;
} else {
if (val > CH1115_MAX_HEIGHT - 1) {
dev_err(dev, "chipwealth,offset=%d must be [0-%d]\n",
val, CH1115_MAX_HEIGHT - 1);
return -EINVAL;
}
ch1115->y_start_offset = (u8)val;
}When ch1115_encoder_atomic_enable() calls ch1115_oled_init() with flip_vertical set to false and y_start_offset set to 0, the expression CH1115_MAX_HEIGHT - ch1115->y_start_offset evaluates to 64 (0x40), which overflows the 6-bit [0, 63] vertical offset field instead of wrapping modulo CH1115_MAX_HEIGHT to 0.
[ ... ]
Quoted 22 lines
drivers/gpu/drm/tiny/ch1115-i2c.c new file +22
-0+static void ch1115_encoder_atomic_enable (struct drm_encoder *encoder, +struct drm_atomic_commit *state) +{ +struct drm_device *drm = encoder->dev; +struct ch1115_device *ch1115 =drm_to_ch1115 (drm); +int ret; + + ret =ch1115_oled_init (ch1115); +if (ret <0 ) +return ; + +u8 command =CH1115_CMD_ON ; + + ret =ch1115_send_command_list (ch1115, &command,1 ); +if (ret <0 ) +return ; + +backlight_enable (ch1115->bl_dev); +} + +static void ch1115_encoder_atomic_disable (struct drm_encoder *encoder, +struct drm_atomic_commit *state)
drivers/gpu/drm/tiny/ch1115-i2c.c line 555
Quoted 10 lines
drivers/gpu/drm/tiny/ch1115-i2c.c new file +10
-0+{ +struct drm_device *drm = encoder->dev; +struct ch1115_device *ch1115 =drm_to_ch1115 (drm); + +backlight_disable (ch1115->bl_dev); + +u8 command =CH1115_CMD_OFF ; + +ch1115_send_command_list (ch1115, &command,1 ); +}
[Severity: Medium]
Should ch1115_encoder_atomic_disable() also disable the internal DC-DC converter?
When the encoder is enabled, ch1115_encoder_atomic_enable() calls ch1115_oled_init(), which turns on the DC-DC converter with CH1115_CMD_DC_DC and CH1115_VAL_DC_DC_ON. However, when the display is disabled via KMS or during system shutdown via ch1115_shutdown() -> drm_atomic_helper_shutdown(), ch1115_encoder_atomic_disable() only sends CH1115_CMD_OFF, leaving the DC-DC converter enabled.
By contrast, ch1115_remove() explicitly sends CH1115_CMD_OFF, CH1115_CMD_DC_DC, and CH1115_VAL_DC_DC_OFF after calling drm_atomic_helper_shutdown():
u8 cmd_list[] = {
CH1115_CMD_OFF,
CH1115_CMD_DC_DC,
CH1115_VAL_DC_DC_OFF,
};
drm_dev_unplug(&ch1115->dev);
drm_atomic_helper_shutdown(&ch1115->dev);
ch1115_send_command_list(ch1115, cmd_list, ARRAY_SIZE(cmd_list));If ch1115_encoder_atomic_disable() sent CH1115_CMD_OFF, CH1115_CMD_DC_DC, and CH1115_VAL_DC_DC_OFF, wouldn't that properly power down the DC-DC converter on both KMS disable and ch1115_shutdown(), while avoiding the duplicate command sequence in ch1115_remove()?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v6 2/3] drm/ch1115: add support for Chipwealth CH1115 OLED controller
Hello,
Quoted 59 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] drm/ch1115: out-of-range display offset 64 sent inch1115_oled_init()
- [Medium] drm/ch1115: missing DC-DC disable inch1115_encoder_atomic_disable()--commit
e5268b4f2a7c534421925bdee0145caf63c50632
Author: Nicolás Antinori <[email protected]>drm/ch1115: add support for Chipwealth CH1115 OLED controller
This commit adds a DRM driver for Chipwealth CH1115 monochrome dot matrix OLED panels connected over I2C.
Quoted 6 lines
drivers/gpu/drm/tiny/ch1115-i2c.c new file +0
-0@@ -0,0 +1,859 @@[ ... ]
Quoted 6 lines
drivers/gpu/drm/tiny/ch1115-i2c.c new file +6
-0+static int ch1115_oled_init (struct ch1115_device *ch1115) +{ +u8 commands[] = { +CH1115_CMD_OFF , + +CH1115_CMD_CLOCK_DIVIDE_RATIO ,drivers/gpu/drm/tiny/ch1115-i2c.c line 194
Quoted 10 lines
drivers/gpu/drm/tiny/ch1115-i2c.c new file +10
-0+CH1115_VAL_CLOCK_DIVIDE_RATIO (CH1115_VAL_CLOCK_OSC_FREQ , +CH1115_VAL_CLOCK_DIV_RATIO ), + +CH1115_CMD_MUX_RATIO , + ch1115->height -1 , + +CH1115_CMD_OFFSET , + ch1115->flip_vertical + ? ch1115->y_start_offset + : CH1115_MAX_HEIGHT - ch1115->y_start_offset,[Severity: Medium]
Doesch1115_oled_init()send an out-of-range value forCH1115_CMD_OFFSETwhenflip_verticalis false andy_start_offsetis 0?In
ch1115_parse_dt(),y_start_offsetdefaults to 0 when the chipwealth,offset property is omitted, and is otherwise restricted to [0,CH1115_MAX_HEIGHT- 1] (0 to 63):ret = of_property_read_u32(np, "chipwealth,offset", &val); if (ret) { ch1115->y_start_offset = 0; } else { if (val > CH1115_MAX_HEIGHT - 1) { dev_err(dev, "chipwealth,offset=%d must be [0-%d]\n", val, CH1115_MAX_HEIGHT - 1); return -EINVAL; } ch1115->y_start_offset = (u8)val; }
Quoted 5 lines
When
ch1115_encoder_atomic_enable()callsch1115_oled_init()withflip_verticalset to false andy_start_offsetset to 0, the expressionCH1115_MAX_HEIGHT-ch1115->y_start_offsetevaluates to 64 (0x40), which overflows the 6-bit [0, 63] vertical offset field instead of wrapping moduloCH1115_MAX_HEIGHTto 0.
This is a false positive, the datasheet [1] states that the formula for this command (D3) is 64 - n, where n is a 6 bit number in the range [0, 63]. I did not use a mask for this because the unused bits get ignored.
Quoted 62 lines
[ ... ]
Quoted 22 lines
drivers/gpu/drm/tiny/ch1115-i2c.c new file +22
-0+static void ch1115_encoder_atomic_enable (struct drm_encoder *encoder, +struct drm_atomic_commit *state) +{ +struct drm_device *drm = encoder->dev; +struct ch1115_device *ch1115 =drm_to_ch1115 (drm); +int ret; + + ret =ch1115_oled_init (ch1115); +if (ret <0 ) +return ; + +u8 command =CH1115_CMD_ON ; + + ret =ch1115_send_command_list (ch1115, &command,1 ); +if (ret <0 ) +return ; + +backlight_enable (ch1115->bl_dev); +} + +static void ch1115_encoder_atomic_disable (struct drm_encoder *encoder, +struct drm_atomic_commit *state)drivers/gpu/drm/tiny/ch1115-i2c.c line 555
Quoted 10 lines
drivers/gpu/drm/tiny/ch1115-i2c.c new file +10
-0+{ +struct drm_device *drm = encoder->dev; +struct ch1115_device *ch1115 =drm_to_ch1115 (drm); + +backlight_disable (ch1115->bl_dev); + +u8 command =CH1115_CMD_OFF ; + +ch1115_send_command_list (ch1115, &command,1 ); +}[Severity: Medium]
Shouldch1115_encoder_atomic_disable()also disable the internal DC-DC converter?When the encoder is enabled,
ch1115_encoder_atomic_enable()callsch1115_oled_init(), which turns on the DC-DC converter withCH1115_CMD_DC_DCandCH1115_VAL_DC_DC_ON. However, when the display is disabled via KMS or during system shutdown viach1115_shutdown()->drm_atomic_helper_shutdown(),ch1115_encoder_atomic_disable()only sendsCH1115_CMD_OFF, leaving the DC-DC converter enabled.By contrast,
ch1115_remove()explicitly sendsCH1115_CMD_OFF,CH1115_CMD_DC_DC, andCH1115_VAL_DC_DC_OFFafter callingdrm_atomic_helper_shutdown():u8 cmd_list[] = { CH1115_CMD_OFF, CH1115_CMD_DC_DC, CH1115_VAL_DC_DC_OFF, }; drm_dev_unplug(&ch1115->dev); drm_atomic_helper_shutdown(&ch1115->dev); ch1115_send_command_list(ch1115, cmd_list, ARRAY_SIZE(cmd_list));
Quoted 4 lines
If
ch1115_encoder_atomic_disable()sentCH1115_CMD_OFF,CH1115_CMD_DC_DC, andCH1115_VAL_DC_DC_OFF, wouldn't that properly power down the DC-DC converter on both KMS disable andch1115_shutdown(), while avoiding the duplicate command sequence inch1115_remove()?
I believe this is accurate, apologies for this oversight. I have a local version of this fixed, tested with modetest, unloading the module, rebooting and power off the system entirely. I'll send a v7 in a few days in case there is a review.
Best regards,
Nicolás