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