xref: /openbmc/linux/drivers/gpu/drm/solomon/ssd130x.h (revision c4a7b9b5)
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 __SSD1307X_H__
14 #define __SSD1307X_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 	int need_pwm;
41 	int need_chargepump;
42 	bool page_mode_only;
43 };
44 
45 struct ssd130x_device {
46 	struct drm_device drm;
47 	struct device *dev;
48 	struct drm_display_mode mode;
49 	struct drm_plane primary_plane;
50 	struct drm_crtc crtc;
51 	struct drm_encoder encoder;
52 	struct drm_connector connector;
53 	struct i2c_client *client;
54 
55 	struct regmap *regmap;
56 
57 	const struct ssd130x_deviceinfo *device_info;
58 
59 	unsigned page_address_mode : 1;
60 	unsigned area_color_enable : 1;
61 	unsigned com_invdir : 1;
62 	unsigned com_lrremap : 1;
63 	unsigned com_seq : 1;
64 	unsigned lookup_table_set : 1;
65 	unsigned low_power : 1;
66 	unsigned seg_remap : 1;
67 	u32 com_offset;
68 	u32 contrast;
69 	u32 dclk_div;
70 	u32 dclk_frq;
71 	u32 height;
72 	u8 lookup_table[4];
73 	u32 page_offset;
74 	u32 col_offset;
75 	u32 prechargep1;
76 	u32 prechargep2;
77 
78 	struct backlight_device *bl_dev;
79 	struct pwm_device *pwm;
80 	struct gpio_desc *reset;
81 	struct regulator *vcc_reg;
82 	u32 vcomh;
83 	u32 width;
84 	/* Cached address ranges */
85 	u8 col_start;
86 	u8 col_end;
87 	u8 page_start;
88 	u8 page_end;
89 };
90 
91 extern const struct ssd130x_deviceinfo ssd130x_variants[];
92 
93 struct ssd130x_device *ssd130x_probe(struct device *dev, struct regmap *regmap);
94 void ssd130x_remove(struct ssd130x_device *ssd130x);
95 void ssd130x_shutdown(struct ssd130x_device *ssd130x);
96 
97 #endif /* __SSD1307X_H__ */
98