xref: /linux/drivers/gpu/drm/solomon/ssd130x.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Header file for:
4  * DRM driver for Solomon SSD130x OLED displays
5  *
6  * Copyright 2022 Red Hat Inc.
7  * Author: Javier Martinez Canillas <javierm@redhat.com>
8  *
9  * Based on drivers/video/fbdev/ssd1307fb.c
10  * Copyright 2012 Free Electrons
11  */
12 
13 #ifndef __SSD130X_H__
14 #define __SSD130X_H__
15 
16 #include <drm/drm_connector.h>
17 #include <drm/drm_crtc.h>
18 #include <drm/drm_drv.h>
19 #include <drm/drm_encoder.h>
20 
21 #include <linux/regmap.h>
22 
23 #define SSD13XX_DATA				0x40
24 #define SSD13XX_COMMAND				0x80
25 
26 enum ssd130x_family_ids {
27 	SSD130X_FAMILY,
28 	SSD132X_FAMILY,
29 	SSD133X_FAMILY
30 };
31 
32 enum ssd130x_variants {
33 	/* ssd130x family */
34 	SH1106_ID,
35 	SSD1305_ID,
36 	SSD1306_ID,
37 	SSD1307_ID,
38 	SSD1309_ID,
39 	/* ssd132x family */
40 	SSD1322_ID,
41 	SSD1325_ID,
42 	SSD1327_ID,
43 	/* ssd133x family */
44 	SSD1331_ID,
45 	NR_SSD130X_VARIANTS
46 };
47 
48 struct ssd130x_deviceinfo {
49 	u32 default_vcomh;
50 	u32 default_dclk_div;
51 	u32 default_dclk_frq;
52 	u32 default_width;
53 	u32 default_height;
54 	bool need_pwm;
55 	bool need_chargepump;
56 	bool page_mode_only;
57 
58 	enum ssd130x_family_ids family_id;
59 };
60 
61 struct ssd130x_device {
62 	struct drm_device drm;
63 	struct device *dev;
64 	struct drm_display_mode mode;
65 	struct drm_plane primary_plane;
66 	struct drm_crtc crtc;
67 	struct drm_encoder encoder;
68 	struct drm_connector connector;
69 	struct i2c_client *client;
70 
71 	struct regmap *regmap;
72 
73 	const struct ssd130x_deviceinfo *device_info;
74 
75 	unsigned page_address_mode : 1;
76 	unsigned area_color_enable : 1;
77 	unsigned com_invdir : 1;
78 	unsigned com_lrremap : 1;
79 	unsigned com_seq : 1;
80 	unsigned lookup_table_set : 1;
81 	unsigned low_power : 1;
82 	unsigned seg_remap : 1;
83 	u32 com_offset;
84 	u32 contrast;
85 	u32 dclk_div;
86 	u32 dclk_frq;
87 	u32 height;
88 	u8 lookup_table[4];
89 	u32 page_offset;
90 	u32 col_offset;
91 	u32 prechargep1;
92 	u32 prechargep2;
93 
94 	struct backlight_device *bl_dev;
95 	struct pwm_device *pwm;
96 	struct gpio_desc *reset;
97 	struct regulator *vcc_reg;
98 	u32 vcomh;
99 	u32 width;
100 	/* Cached address ranges */
101 	u8 col_start;
102 	u8 col_end;
103 	u8 page_start;
104 	u8 page_end;
105 };
106 
107 extern const struct ssd130x_deviceinfo ssd130x_variants[];
108 
109 struct ssd130x_device *ssd130x_probe(struct device *dev, struct regmap *regmap);
110 void ssd130x_remove(struct ssd130x_device *ssd130x);
111 void ssd130x_shutdown(struct ssd130x_device *ssd130x);
112 
113 #endif /* __SSD130X_H__ */
114