| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- /* SPDX-License-Identifier: GPL-2.0-only */
- /*
- * S1D13700 behind a TCA9539: hardware-independent panel core.
- *
- * Shared by the DRM driver, the i2c-dev frontend, the GTK simulator and the
- * tests. It owns everything between "new frame in native format" and "bytes
- * for one I2C write", and has no kernel or libc dependency beyond memcmp().
- *
- * Wire format: every write starts with the Output Port 0 command byte, then
- * alternates P0 (LCD data) and P1 (LCD control), relying on the TCA9539
- * staying within the addressed register pair. Each transfer therefore holds
- * an odd number of bytes and always restarts at P0.
- */
- #ifndef S1D13700_CORE_H
- #define S1D13700_CORE_H
- #ifdef __KERNEL__
- #include <linux/types.h>
- #else
- #include <stdbool.h>
- #include <stddef.h>
- #include <stdint.h>
- #endif
- /* TCA9539 command bytes */
- #define TCA_REG_OUTPUT0 0x02
- #define TCA_REG_POLARITY0 0x04
- #define TCA_REG_CONFIG0 0x06
- /* U1 port 1: LCD control lines (module pin names in brackets) */
- #define S1D_P1_BL 0x01 /* backlight enable, active high */
- #define S1D_P1_RES 0x02 /* RES# [RST] */
- #define S1D_P1_A0 0x04 /* [A15]: 1 = command, 0 = parameter/data */
- #define S1D_P1_WR 0x08 /* WR# [WE] */
- #define S1D_P1_RD 0x10 /* RD# [RE] */
- #define S1D_P1_CS 0x20 /* CS# [CS0] */
- #define S1D_P1_CONFIG 0xc0 /* P1.6-7 unused: stay inputs */
- /* S1D13700 indirect-mode commands */
- #define S1D_CMD_SYSTEM_SET 0x40
- #define S1D_CMD_MWRITE 0x42
- #define S1D_CMD_MREAD 0x43
- #define S1D_CMD_SCROLL 0x44
- #define S1D_CMD_CSRW 0x46
- #define S1D_CMD_CSRR 0x47
- #define S1D_CMD_CSRDIR_R 0x4c
- #define S1D_CMD_CSRDIR_L 0x4d
- #define S1D_CMD_CSRDIR_U 0x4e
- #define S1D_CMD_CSRDIR_D 0x4f
- #define S1D_CMD_SLEEP 0x53
- #define S1D_CMD_DISP_OFF 0x58
- #define S1D_CMD_DISP_ON 0x59
- #define S1D_CMD_HDOT_SCR 0x5a
- #define S1D_CMD_OVLAY 0x5b
- #define S1D_CMD_CGRAM_ADR 0x5c
- #define S1D_CMD_CSRFORM 0x5d
- #define S1D_CMD_GRAYSCALE 0x60
- #define S1D_VRAM_SIZE 32768u
- /*
- * Rewriting an unchanged gap costs one LCD write per byte; seeking costs
- * CSRW + 2 parameters + MWRITE (4 writes, 16 I2C bytes) plus four A0
- * transitions of one extra P0/P1 pair each (8 I2C bytes). That is 24 I2C
- * bytes, the same as 6 data bytes.
- */
- #define S1D_SEEK_COST 6u
- #define S1D_DIR_COST 1u
- struct s1d_config {
- unsigned int width; /* pixels, multiple of the pixels in one byte */
- unsigned int height;
- unsigned int bpp; /* 1, 2 or 4 */
- unsigned int tcr; /* SYSTEM SET TC/R: tune for frame rate */
- };
- struct s1d_ops {
- /* buf[0] is the TCA9539 command byte; the transport adds the address */
- int (*xfer)(void *ctx, const uint8_t *buf, size_t len);
- void (*delay_ms)(void *ctx, unsigned int ms);
- };
- /*
- * Wrapping counters: unsigned long for debugfs_create_ulong(), so 32 bits on
- * the target, where i2c_bytes wraps after about a day of continuous traffic
- * at 400 kHz. Read them as differences between two samples.
- */
- struct s1d_stats {
- unsigned long writes; /* LCD bus cycles */
- unsigned long data_bytes; /* of which display memory */
- unsigned long seeks;
- unsigned long dir_changes;
- unsigned long i2c_msgs;
- unsigned long i2c_bytes; /* payload, including command bytes */
- };
- struct s1d_panel {
- struct s1d_config cfg;
- unsigned int stride;
- unsigned int size;
- const struct s1d_ops *ops;
- void *ctx;
- uint8_t *shadow; /* what the panel holds; cfg-sized */
- uint8_t *tx;
- size_t tx_cap;
- size_t tx_len;
- uint8_t p1; /* last control byte queued; WR high between writes */
- uint8_t p1_sent; /* last control byte the expander acknowledged */
- bool vertical; /* cursor direction currently programmed */
- bool backlight; /* S1D_P1_BL level to keep driving */
- bool force_full; /* shadow cannot be trusted: rewrite everything */
- int err; /* first transport error of the current operation */
- struct s1d_stats stats;
- };
- /* Native framebuffer size for a configuration; 0 if it is not valid. */
- unsigned int s1d_frame_size(const struct s1d_config *cfg);
- /*
- * shadow must hold s1d_frame_size() bytes; tx is the transfer buffer and must
- * be DMA-safe in the kernel. tx_cap limits one I2C message (at least 7).
- */
- int s1d_panel_setup(struct s1d_panel *p, const struct s1d_config *cfg,
- const struct s1d_ops *ops, void *ctx,
- uint8_t *shadow, uint8_t *tx, size_t tx_cap);
- /* Program the expander, reset and configure the controller, clear VRAM. */
- int s1d_panel_init(struct s1d_panel *p);
- /*
- * Bring rows [y0, y1) of the panel up to date with the native frame "next",
- * sending only what differs from the shadow. After a transport error the next
- * call rewrites the whole frame, so "next" must always be a complete frame.
- */
- int s1d_panel_update(struct s1d_panel *p, const uint8_t *next,
- unsigned int y0, unsigned int y1);
- int s1d_panel_display(struct s1d_panel *p, bool on);
- /* Backlight pin on the expander. Applied at once if the panel is set up. */
- int s1d_panel_backlight(struct s1d_panel *p, bool on);
- /*
- * Program a raw controller command, for bring-up experiments. CSRDIR_L and
- * CSRDIR_U are refused, since the update planner only knows right and down.
- */
- int s1d_panel_command(struct s1d_panel *p, uint8_t cmd,
- const uint8_t *params, size_t nparams);
- /*
- * Convert XRGB8888 pixels to the native format: white is level 0 (pixel off),
- * black the highest level, leftmost pixel in the most significant bits. The
- * rectangle is widened to whole bytes; src must cover those pixels.
- */
- void s1d_convert_xrgb8888(const struct s1d_config *cfg, const void *src,
- unsigned int pitch, uint8_t *dst,
- unsigned int x0, unsigned int y0,
- unsigned int x1, unsigned int y1);
- #ifndef __KERNEL__
- /* Approximate bus time in microseconds at the given SCL rate. */
- uint64_t s1d_stats_bus_us(const struct s1d_stats *st, unsigned int scl_hz);
- #endif
- #endif /* S1D13700_CORE_H */
|