|
|
2 тижнів тому | |
|---|---|---|
| docs | 2 тижнів тому | |
| driver | 2 тижнів тому | |
| dts | 2 тижнів тому | |
| sim | 2 тижнів тому | |
| tests | 2 тижнів тому | |
| .gitignore | 2 тижнів тому | |
| LICENSE | 2 тижнів тому | |
| Makefile | 2 тижнів тому | |
| README.md | 2 тижнів тому |
A Linux DRM driver for an Epson S1D13700 (SED1335 family) graphic LCD whose 8080-style parallel bus is driven through a TI TCA9539 16-bit I²C GPIO expander, plus the parts that make it testable without hardware:
driver/s1d13700_core.*) that the
driver uses and userspace can link as well,sim/) that decodes the I²C byte stream as a TCA9539 and
S1D13700 would and flags bus protocol faults,It was written for a 240×160 panel at 2 bpp on an Orange Pi Zero (Allwinner
H2+, 400 kHz I²C) and runs there, built into the kernel, with fbcon on the
panel. The radio-ui application (sibling repository radio-ui) uses the
same core from userspace, over i2c-dev or through this driver.
| Path | What |
|---|---|
driver/s1d13700_core.* |
Panel core: init, XRGB8888 to 1/2/4 bpp, write planner, TCA9539 stream encoder |
driver/s1d13700_drm.c |
Atomic KMS driver with fbdev emulation and a backlight device |
driver/Kbuild |
Out-of-tree build |
sim/ |
Model of the TCA9539 and S1D13700 interface, with fault counters |
tests/test_panel.c |
Core tests against the simulator |
dts/radio-panel.dts |
Overlay: the panel |
dts/examples/orangepi-zero-i2c1.dtsi |
The same for a board DT, as used on the Orange Pi Zero |
docs/s1d13700-recommendations.md |
Review of the core and driver, applied |
make test # core tests, no hardware or libraries
make asan # the same under ASan and UBSan
make module KDIR=/path/to/kernel
make dtbo # build/*.dtbo from dts/*.dts
The driver needs a 6.x kernel with damage helpers, drm_fbdev_shmem and the
DRM client setup (built against 6.18 and 7.3). It does not build on 4.19;
there the panel can still be driven from userspace through i2c-dev with the
core.
Copy driver/s1d13700_drm.c, s1d13700_core.c and s1d13700_core.h into
e.g. drivers/gpu/drm/tiny/s1d13700-tca/ and add:
# Kconfig
config DRM_S1D13700_TCA
tristate "S1D13700 panel behind a TCA9539 I2C expander"
depends on DRM && I2C
select DRM_CLIENT_SELECTION
select DRM_KMS_HELPER
select DRM_GEM_SHMEM_HELPER
select BACKLIGHT_CLASS_DEVICE
# Makefile
obj-$(CONFIG_DRM_S1D13700_TCA) += s1d13700-tca.o
s1d13700-tca-y := s1d13700_drm.o s1d13700_core.o
The Orange Pi Zero build scripts (build-kernel.sh in the OPi0 project) do
this on every build and set it to built-in, so fbcon shows the boot log on
the panel. Linux 7.3 renamed struct drm_atomic_state to
struct drm_atomic_commit; that script force-includes a small compatibility
header into s1d13700_drm.c rather than changing the source.
Binding: I²C client, compatible = "k4be,s1d13700-tca9539" (k4be is
not a registered vendor prefix, so dtbs_check warns), or I²C id
s1d13700-tca9539 for new_device:
echo s1d13700-tca9539 0x74 > /sys/bus/i2c/devices/i2c-N/new_device
Module parameters (read-only, so kernel arguments when built in, e.g.
s1d13700_tca.tcr=162):
| Parameter | Default | |
|---|---|---|
| width, height | 240, 160 | panel size in pixels |
| bpp | 2 | 1, 2 or 4 bits per pixel |
| tcr | 162 | SYSTEM SET TC/R, sets the frame rate |
max_write_len is honoured. A failed transfer makes the next
update rewrite the frame; a failed init is retried.Backlight: expander pin P1.0 is registered as
/sys/class/backlight/radio-backlight (brightness 0 or 1, on at probe).
The sysfs file is root:root 0644; a udev rule can open it to a group:
ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="radio-backlight", RUN+="/bin/chgrp video /sys%p/brightness", RUN+="/bin/chmod g+w /sys%p/brightness"
Statistics in debugfs, under the I²C client's directory:
lcd_writes, data_bytes, seeks, dir_changes, i2c_msgs, i2c_bytes.
Blanking is display off only; the controller's SLEEP is not used.
Only one driver can own an I²C address: U1 must not be bound to
gpio-pca953x. The driver needs one continuous write that alternates both
expander ports, which the GPIO API cannot express (going through it would
cost roughly 2.5-3× more bus time per LCD byte).
U1, TCA9539 at 0x74 (A1=L, A0=L), the driver's I²C client:
| Pin | Signal | Module pin |
|---|---|---|
| P0.0-7 | D0-D7 | D0-D7 |
| P1.0 | Backlight enable (active high) | |
| P1.1 | RES# | RST |
| P1.2 | A0 | A15 |
| P1.3 | WR# | WE |
| P1.4 | RD# | RE |
| P1.5 | CS# (held low after reset) | CS0 |
| P1.6-7 | spare |
The pin assignment is fixed in s1d13700_core.h.
The keys on the same bus (U2, a second TCA9539 at 0x76, with stock
gpio-pca953x and gpio-keys) are in the sibling repository
radio-keyboard-tca: wiring, key map and device tree.
dts/radio-panel.dts is an overlay written with plain numbers instead of
#include, so it also works with armbian-add-overlay. It targets i2c0;
check that against the board. For the i2c-dev userspace path, do not load it.
dts/examples/orangepi-zero-i2c1.dtsi is the version in use on the Orange Pi
Zero, for inclusion in a board DTS: i2c1 at 400 kHz and the panel. The keys'
overlay and board fragment are in radio-keyboard-tca.
0x02, then
alternates P0 (data) and P1 (control). Each LCD cycle is
data, WR=0, data, WR=1. A0 changes get their own P0/P1 pair with WR# high,
because A0 needs setup time before the WR# edge and shares a port with it. A
cycle is never split across messages, so WR# is not left low when the bus is
released.FX=7 and HDOT=0 (required above
1 bpp), CM=1 (required in graphics mode), grayscale value 1. VRAM is
cleared before the display is turned on.CSRDIR down),
whichever is cheaper. Unchanged gaps up to 6 bytes (the cost of a seek) are
rewritten rather than skipped.i2c_master_send() in
the driver, I2C_RDWR on i2c-dev, or the simulator.Models the TCA9539 register pairs and the S1D13700 indirect interface from the I²C bytes alone. It counts faults: A0 changing with a WR# edge, parameters with no command or too many, unknown commands, bad registers, messages ending between P0 and P1, inconsistent SYSTEM SET, and writes during reset. It also models the cursor behaviour above.
| Update (240×160, 2 bpp, 400 kHz) | I²C bytes | Bus time |
|---|---|---|
| One 8×13 digit | 169 | 3.8 ms |
| Full frame | 38 474 (38 messages) | 867 ms |
| Typical small UI update | 113-177 | 2.6-4.0 ms |
Calculated from the bytes sent on an ideal bus; real timing is slower. The
Allwinner i2c-mv64xxx takes about one interrupt per byte.
make test covers: init values, invalid configurations, no change means no
traffic, direction choice, gap merging, 2000 random update rounds at 1/2/4 bpp
and message sizes 7/61/1025, transport and backlight failure recovery, lost
direction recovery, pixel conversion, the simulator's renderer and its fault
detector. They also pass under ASan and UBSan.
drivers/gpu/drm/sitronix/st7571-i2c.cGPL-2.0-only (see LICENSE and the SPDX headers).