xref: /linux/drivers/gpu/drm/solomon/ssd130x.h (revision 021bc4b9)
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 };
30 
31 enum ssd130x_variants {
32 	/* ssd130x family */
33 	SH1106_ID,
34 	SSD1305_ID,
35 	SSD1306_ID,
36 	SSD1307_ID,
37 	SSD1309_ID,
38 	/* ssd132x family */
39 	SSD1322_ID,
40 	SSD1325_ID,
41 	SSD1327_ID,
42 	NR_SSD130X_VARIANTS
43 };
44 
45 struct ssd130x_deviceinfo {
46 	u32 default_vcomh;
47 	u32 default_dclk_div;
48 	u32 default_dclk_frq;
49 	u32 default_width;
50 	u32 default_height;
51 	bool need_pwm;
52 	bool need_chargepump;
53 	bool page_mode_only;
54 
55 	enum ssd130x_family_ids family_id;
56 };
57 
58 struct ssd130x_device {
59 	struct drm_device drm;
60 	struct device *dev;
61 	struct drm_display_mode mode;
62 	struct drm_plane primary_plane;
63 	struct drm_crtc crtc;
64 	struct drm_encoder encoder;
65 	struct drm_connector connector;
66 	struct i2c_client *client;
67 
68 	struct regmap *regmap;
69 
70 	const struct ssd130x_deviceinfo *device_info;
71 
72 	unsigned page_address_mode : 1;
73 	unsigned area_color_enable : 1;
74 	unsigned com_invdir : 1;
75 	unsigned com_lrremap : 1;
76 	unsigned com_seq : 1;
77 	unsigned lookup_table_set : 1;
78 	unsigned low_power : 1;
79 	unsigned seg_remap : 1;
80 	u32 com_offset;
81 	u32 contrast;
82 	u32 dclk_div;
83 	u32 dclk_frq;
84 	u32 height;
85 	u8 lookup_table[4];
86 	u32 page_offset;
87 	u32 col_offset;
88 	u32 prechargep1;
89 	u32 prechargep2;
90 
91 	struct backlight_device *bl_dev;
92 	struct pwm_device *pwm;
93 	struct gpio_desc *reset;
94 	struct regulator *vcc_reg;
95 	u32 vcomh;
96 	u32 width;
97 	/* Cached address ranges */
98 	u8 col_start;
99 	u8 col_end;
100 	u8 page_start;
101 	u8 page_end;
102 };
103 
104 extern const struct ssd130x_deviceinfo ssd130x_variants[];
105 
106 struct ssd130x_device *ssd130x_probe(struct device *dev, struct regmap *regmap);
107 void ssd130x_remove(struct ssd130x_device *ssd130x);
108 void ssd130x_shutdown(struct ssd130x_device *ssd130x);
109 
110 #endif /* __SSD130X_H__ */
111