xref: /linux/drivers/gpu/drm/sitronix/st7571.h (revision ca220141fa8ebae09765a242076b2b77338106b0)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Header file for:
4  * Driver for Sitronix ST7571, a 4 level gray scale dot matrix LCD controller
5  *
6  * Copyright (C) 2025 Marcus Folkesson <marcus.folkesson@gmail.com>
7  */
8 
9 #ifndef __ST7571_H__
10 #define __ST7571_H__
11 
12 #include <drm/drm_connector.h>
13 #include <drm/drm_crtc.h>
14 #include <drm/drm_drv.h>
15 #include <drm/drm_encoder.h>
16 #include <drm/drm_format_helper.h>
17 
18 #include <linux/regmap.h>
19 
20 enum st7571_color_mode {
21 	ST7571_COLOR_MODE_GRAY = 0,
22 	ST7571_COLOR_MODE_BLACKWHITE = 1,
23 };
24 
25 struct st7571_device;
26 
27 struct st7571_panel_constraints {
28 	u32 min_nlines;
29 	u32 max_nlines;
30 	u32 min_ncols;
31 	u32 max_ncols;
32 	bool support_grayscale;
33 };
34 
35 struct st7571_panel_data {
36 	int (*init)(struct st7571_device *st7571);
37 	int (*parse_dt)(struct st7571_device *st7571);
38 	struct st7571_panel_constraints constraints;
39 };
40 
41 struct st7571_panel_format {
42 	void (*prepare_buffer)(struct st7571_device *st7571,
43 			       const struct iosys_map *vmap,
44 			       struct drm_framebuffer *fb,
45 			       struct drm_rect *rect,
46 			       struct drm_format_conv_state *fmtcnv_state);
47 	int (*update_rect)(struct drm_framebuffer *fb, struct drm_rect *rect);
48 	enum st7571_color_mode mode;
49 	const u8 nformats;
50 	const u32 formats[];
51 };
52 
53 struct st7571_device {
54 	struct drm_device drm;
55 	struct device *dev;
56 
57 	struct drm_plane primary_plane;
58 	struct drm_crtc crtc;
59 	struct drm_encoder encoder;
60 	struct drm_connector connector;
61 
62 	struct drm_display_mode mode;
63 
64 	const struct st7571_panel_format *pformat;
65 	const struct st7571_panel_data *pdata;
66 	struct gpio_desc *reset;
67 	struct regmap *regmap;
68 
69 	bool grayscale;
70 	bool inverted;
71 	u32 height_mm;
72 	u32 width_mm;
73 	u32 startline;
74 	u32 nlines;
75 	u32 ncols;
76 	u32 bpp;
77 
78 	/* Intermediate buffer in LCD friendly format */
79 	u8 *hwbuf;
80 
81 	/* Row of (transformed) pixels ready to be written to the display */
82 	u8 *row;
83 };
84 
85 extern const struct st7571_panel_data st7567_config;
86 extern const struct st7571_panel_data st7571_config;
87 
88 struct st7571_device *st7571_probe(struct device *dev, struct regmap *regmap);
89 void st7571_remove(struct st7571_device *st7571);
90 
91 #endif /* __ST7571_H__ */
92