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