1 // SPDX-License-Identifier: GPL-2.0
3 * FB driver for the WiseChip Semiconductor Inc. (UG-6028GDEBF02) display
4 * using the SEPS525 (Syncoam) LCD Controller
6 * Copyright (C) 2020 Xilinx Inc.
17 #include <dm/device_compat.h>
18 #include <linux/delay.h>
23 #define SEPS525_INDEX 0x00
24 #define SEPS525_STATUS_RD 0x01
25 #define SEPS525_OSC_CTL 0x02
26 #define SEPS525_IREF 0x80
27 #define SEPS525_CLOCK_DIV 0x03
28 #define SEPS525_REDUCE_CURRENT 0x04
29 #define SEPS525_SOFT_RST 0x05
30 #define SEPS525_DISP_ONOFF 0x06
31 #define SEPS525_PRECHARGE_TIME_R 0x08
32 #define SEPS525_PRECHARGE_TIME_G 0x09
33 #define SEPS525_PRECHARGE_TIME_B 0x0A
34 #define SEPS525_PRECHARGE_CURRENT_R 0x0B
35 #define SEPS525_PRECHARGE_CURRENT_G 0x0C
36 #define SEPS525_PRECHARGE_CURRENT_B 0x0D
37 #define SEPS525_DRIVING_CURRENT_R 0x10
38 #define SEPS525_DRIVING_CURRENT_G 0x11
39 #define SEPS525_DRIVING_CURRENT_B 0x12
40 #define SEPS525_DISPLAYMODE_SET 0x13
41 #define SEPS525_RGBIF 0x14
42 #define SEPS525_RGB_POL 0x15
43 #define SEPS525_MEMORY_WRITEMODE 0x16
44 #define SEPS525_MX1_ADDR 0x17
45 #define SEPS525_MX2_ADDR 0x18
46 #define SEPS525_MY1_ADDR 0x19
47 #define SEPS525_MY2_ADDR 0x1A
48 #define SEPS525_MEMORY_ACCESS_POINTER_X 0x20
49 #define SEPS525_MEMORY_ACCESS_POINTER_Y 0x21
50 #define SEPS525_DDRAM_DATA_ACCESS_PORT 0x22
51 #define SEPS525_GRAY_SCALE_TABLE_INDEX 0x50
52 #define SEPS525_GRAY_SCALE_TABLE_DATA 0x51
53 #define SEPS525_DUTY 0x28
54 #define SEPS525_DSL 0x29
55 #define SEPS525_D1_DDRAM_FAC 0x2E
56 #define SEPS525_D1_DDRAM_FAR 0x2F
57 #define SEPS525_D2_DDRAM_SAC 0x31
58 #define SEPS525_D2_DDRAM_SAR 0x32
59 #define SEPS525_SCR1_FX1 0x33
60 #define SEPS525_SCR1_FX2 0x34
61 #define SEPS525_SCR1_FY1 0x35
62 #define SEPS525_SCR1_FY2 0x36
63 #define SEPS525_SCR2_SX1 0x37
64 #define SEPS525_SCR2_SX2 0x38
65 #define SEPS525_SCR2_SY1 0x39
66 #define SEPS525_SCR2_SY2 0x3A
67 #define SEPS525_SCREEN_SAVER_CONTEROL 0x3B
68 #define SEPS525_SS_SLEEP_TIMER 0x3C
69 #define SEPS525_SCREEN_SAVER_MODE 0x3D
70 #define SEPS525_SS_SCR1_FU 0x3E
71 #define SEPS525_SS_SCR1_MXY 0x3F
72 #define SEPS525_SS_SCR2_FU 0x40
73 #define SEPS525_SS_SCR2_MXY 0x41
74 #define SEPS525_MOVING_DIRECTION 0x42
75 #define SEPS525_SS_SCR2_SX1 0x47
76 #define SEPS525_SS_SCR2_SX2 0x48
77 #define SEPS525_SS_SCR2_SY1 0x49
78 #define SEPS525_SS_SCR2_SY2 0x4A
80 /* SEPS525_DISPLAYMODE_SET */
81 #define MODE_SWAP_BGR BIT(7)
82 #define MODE_SM BIT(6)
83 #define MODE_RD BIT(5)
84 #define MODE_CD BIT(4)
87 * struct seps525_priv - Private structure
88 * @reset_gpio: Reset gpio pin
89 * @dc_gpio: Data/command control gpio pin
90 * @dev: Device uclass for video_ops
93 struct gpio_desc reset_gpio;
94 struct gpio_desc dc_gpio;
98 static int seps525_spi_write_cmd(struct udevice *dev, u32 reg)
100 struct seps525_priv *priv = dev_get_priv(dev);
104 ret = dm_gpio_set_value(&priv->dc_gpio, 0);
106 dev_dbg(dev, "Failed to handle dc\n");
110 ret = dm_spi_xfer(dev, 8, &buf8, NULL, SPI_XFER_BEGIN | SPI_XFER_END);
112 dev_dbg(dev, "Failed to write command\n");
117 static int seps525_spi_write_data(struct udevice *dev, u32 val)
119 struct seps525_priv *priv = dev_get_priv(dev);
123 ret = dm_gpio_set_value(&priv->dc_gpio, 1);
125 dev_dbg(dev, "Failed to handle dc\n");
129 ret = dm_spi_xfer(dev, 8, &buf8, NULL, SPI_XFER_BEGIN | SPI_XFER_END);
131 dev_dbg(dev, "Failed to write data\n");
136 static void seps525_spi_write(struct udevice *dev, u32 reg, u32 val)
138 (void)seps525_spi_write_cmd(dev, reg);
139 (void)seps525_spi_write_data(dev, val);
142 static int seps525_display_init(struct udevice *dev)
144 /* Disable Oscillator Power Down */
145 seps525_spi_write(dev, SEPS525_REDUCE_CURRENT, 0x03);
148 /* Set Normal Driving Current */
149 seps525_spi_write(dev, SEPS525_REDUCE_CURRENT, 0x00);
152 seps525_spi_write(dev, SEPS525_SCREEN_SAVER_CONTEROL, 0x00);
153 /* Set EXPORT1 Pin at Internal Clock */
154 seps525_spi_write(dev, SEPS525_OSC_CTL, 0x01);
155 /* Set Clock as 120 Frames/Sec */
156 seps525_spi_write(dev, SEPS525_CLOCK_DIV, 0x90);
157 /* Set Reference Voltage Controlled by External Resister */
158 seps525_spi_write(dev, SEPS525_IREF, 0x01);
160 /* precharge time R G B */
161 seps525_spi_write(dev, SEPS525_PRECHARGE_TIME_R, 0x04);
162 seps525_spi_write(dev, SEPS525_PRECHARGE_TIME_G, 0x05);
163 seps525_spi_write(dev, SEPS525_PRECHARGE_TIME_B, 0x05);
165 /* precharge current R G B (uA) */
166 seps525_spi_write(dev, SEPS525_PRECHARGE_CURRENT_R, 0x9D);
167 seps525_spi_write(dev, SEPS525_PRECHARGE_CURRENT_G, 0x8C);
168 seps525_spi_write(dev, SEPS525_PRECHARGE_CURRENT_B, 0x57);
170 /* driving current R G B (uA) */
171 seps525_spi_write(dev, SEPS525_DRIVING_CURRENT_R, 0x56);
172 seps525_spi_write(dev, SEPS525_DRIVING_CURRENT_G, 0x4D);
173 seps525_spi_write(dev, SEPS525_DRIVING_CURRENT_B, 0x46);
174 /* Set Color Sequence */
175 seps525_spi_write(dev, SEPS525_DISPLAYMODE_SET, 0x00);
176 /* Set MCU Interface Mode */
177 seps525_spi_write(dev, SEPS525_RGBIF, 0x01);
178 /* Set Memory Write Mode */
179 seps525_spi_write(dev, SEPS525_MEMORY_WRITEMODE, 0x66);
180 /* 1/128 Duty (0x0F~0x7F) */
181 seps525_spi_write(dev, SEPS525_DUTY, 0x7F);
182 /* Set Mapping RAM Display Start Line (0x00~0x7F) */
183 seps525_spi_write(dev, SEPS525_DSL, 0x00);
184 /* Display On (0x00/0x01) */
185 seps525_spi_write(dev, SEPS525_DISP_ONOFF, 0x01);
186 /* Set All Internal Register Value as Normal Mode */
187 seps525_spi_write(dev, SEPS525_SOFT_RST, 0x00);
188 /* Set RGB Interface Polarity as Active Low */
189 seps525_spi_write(dev, SEPS525_RGB_POL, 0x00);
191 /* Enable access for data */
192 (void)seps525_spi_write_cmd(dev, SEPS525_DDRAM_DATA_ACCESS_PORT);
197 static int seps525_spi_startup(struct udevice *dev)
199 struct seps525_priv *priv = dev_get_priv(dev);
202 ret = dm_gpio_set_value(&priv->reset_gpio, 1);
206 ret = dm_gpio_set_value(&priv->reset_gpio, 0);
210 ret = dm_spi_claim_bus(dev);
212 dev_err(dev, "Failed to claim SPI bus: %d\n", ret);
216 ret = seps525_display_init(dev);
220 dm_spi_release_bus(dev);
225 static int seps525_sync(struct udevice *vid)
227 struct video_priv *uc_priv = dev_get_uclass_priv(vid);
228 struct seps525_priv *priv = dev_get_priv(vid);
229 struct udevice *dev = priv->dev;
232 u8 *start = uc_priv->fb;
234 ret = dm_spi_claim_bus(dev);
236 dev_err(dev, "Failed to claim SPI bus: %d\n", ret);
240 /* start position X,Y */
241 seps525_spi_write(dev, SEPS525_MEMORY_ACCESS_POINTER_X, 0);
242 seps525_spi_write(dev, SEPS525_MEMORY_ACCESS_POINTER_Y, 0);
244 /* Enable access for data */
245 (void)seps525_spi_write_cmd(dev, SEPS525_DDRAM_DATA_ACCESS_PORT);
247 for (i = 0; i < (uc_priv->xsize * uc_priv->ysize); i++) {
250 (void)seps525_spi_write_data(dev, data1);
251 (void)seps525_spi_write_data(dev, data2);
254 dm_spi_release_bus(dev);
259 static int seps525_probe(struct udevice *dev)
261 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
262 struct seps525_priv *priv = dev_get_priv(dev);
266 buswidth = dev_read_u32_default(dev, "buswidth", 0);
268 dev_err(dev, "Only 8bit buswidth is supported now");
272 ret = gpio_request_by_name(dev, "reset-gpios", 0,
273 &priv->reset_gpio, GPIOD_IS_OUT);
275 dev_err(dev, "missing reset GPIO\n");
279 ret = gpio_request_by_name(dev, "dc-gpios", 0,
280 &priv->dc_gpio, GPIOD_IS_OUT);
282 dev_err(dev, "missing dc GPIO\n");
286 uc_priv->bpix = VIDEO_BPP16;
287 uc_priv->xsize = WIDTH;
288 uc_priv->ysize = HEIGHT;
293 ret = seps525_spi_startup(dev);
300 static int seps525_bind(struct udevice *dev)
302 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
304 plat->size = WIDTH * HEIGHT * 16;
309 static const struct video_ops seps525_ops = {
310 .video_sync = seps525_sync,
313 static const struct udevice_id seps525_ids[] = {
314 { .compatible = "syncoam,seps525" },
318 U_BOOT_DRIVER(seps525_video) = {
319 .name = "seps525_video",
321 .of_match = seps525_ids,
323 .plat_auto = sizeof(struct video_uc_plat),
324 .bind = seps525_bind,
325 .probe = seps525_probe,
326 .priv_auto = sizeof(struct seps525_priv),