1 // SPDX-License-Identifier: GPL-2.0+
3 * FB driver for the UC1701 LCD Controller
5 * The display is monochrome and the video memory is RGB565.
6 * Any pixel value except 0 turns the pixel on.
8 * Copyright (C) 2014 Juergen Holzmann
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/gpio.h>
15 #include <linux/spi/spi.h>
16 #include <linux/delay.h>
20 #define DRVNAME "fb_uc1701"
23 #define PAGES (HEIGHT / 8)
25 /* 1: Display on/off */
26 #define LCD_DISPLAY_ENABLE 0xAE
27 /* 2: display start line set */
28 #define LCD_START_LINE 0x40
29 /* 3: Page address set (lower 4 bits select one of the pages) */
30 #define LCD_PAGE_ADDRESS 0xB0
31 /* 4: column address */
32 #define LCD_COL_ADDRESS 0x10
33 /* 8: select orientation */
34 #define LCD_BOTTOMVIEW 0xA0
35 /* 9: inverted display */
36 #define LCD_DISPLAY_INVERT 0xA6
37 /* 10: show memory content or switch all pixels on */
38 #define LCD_ALL_PIXEL 0xA4
39 /* 11: lcd bias set */
41 /* 14: Reset Controller */
42 #define LCD_RESET_CMD 0xE2
43 /* 15: output mode select (turns display upside-down) */
44 #define LCD_SCAN_DIR 0xC0
45 /* 16: power control set */
46 #define LCD_POWER_CONTROL 0x28
47 /* 17: voltage regulator resistor ratio set */
48 #define LCD_VOLTAGE 0x20
49 /* 18: Volume mode set */
50 #define LCD_VOLUME_MODE 0x81
52 #define LCD_NO_OP 0xE3
53 /* 25: advanced program control */
54 #define LCD_ADV_PROG_CTRL 0xFA
55 /* 25: advanced program control2 */
56 #define LCD_ADV_PROG_CTRL2 0x10
57 #define LCD_TEMPCOMP_HIGH 0x80
58 /* column offset for normal orientation */
59 #define SHIFT_ADDR_NORMAL 0
60 /* column offset for bottom view orientation */
61 #define SHIFT_ADDR_TOPVIEW 30
63 static int init_display(struct fbtft_par *par)
65 par->fbtftops.reset(par);
67 /* softreset of LCD */
68 write_reg(par, LCD_RESET_CMD);
72 write_reg(par, LCD_START_LINE);
74 /* select orientation BOTTOMVIEW */
75 write_reg(par, LCD_BOTTOMVIEW | 1);
77 /* output mode select (turns display upside-down) */
78 write_reg(par, LCD_SCAN_DIR | 0x00);
80 /* Normal Pixel mode */
81 write_reg(par, LCD_ALL_PIXEL | 0);
83 /* positive display */
84 write_reg(par, LCD_DISPLAY_INVERT | 0);
87 write_reg(par, LCD_BIAS | 0);
89 /* power control mode: all features on */
90 write_reg(par, LCD_POWER_CONTROL | 0x07);
92 /* set voltage regulator R/R */
93 write_reg(par, LCD_VOLTAGE | 0x07);
96 write_reg(par, LCD_VOLUME_MODE);
98 write_reg(par, LCD_NO_OP);
100 /* advanced program control */
101 write_reg(par, LCD_ADV_PROG_CTRL);
102 write_reg(par, LCD_ADV_PROG_CTRL2 | LCD_TEMPCOMP_HIGH);
105 write_reg(par, LCD_DISPLAY_ENABLE | 1);
110 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
113 write_reg(par, LCD_PAGE_ADDRESS);
114 write_reg(par, 0x00);
115 write_reg(par, LCD_COL_ADDRESS);
118 static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
120 u16 *vmem16 = (u16 *)par->info->screen_buffer;
125 for (y = 0; y < PAGES; y++) {
126 buf = par->txbuf.buf;
127 for (x = 0; x < WIDTH; x++) {
129 for (i = 0; i < 8; i++)
130 *buf |= (vmem16[((y * 8 * WIDTH) +
136 write_reg(par, LCD_PAGE_ADDRESS | (u8)y);
137 write_reg(par, 0x00);
138 write_reg(par, LCD_COL_ADDRESS);
139 gpio_set_value(par->gpio.dc, 1);
140 ret = par->fbtftops.write(par, par->txbuf.buf, WIDTH);
141 gpio_set_value(par->gpio.dc, 0);
145 dev_err(par->info->device, "write failed and returned: %d\n",
151 static struct fbtft_display display = {
156 .init_display = init_display,
157 .set_addr_win = set_addr_win,
158 .write_vmem = write_vmem,
163 FBTFT_REGISTER_DRIVER(DRVNAME, "UltraChip,uc1701", &display);
165 MODULE_ALIAS("spi:" DRVNAME);
166 MODULE_ALIAS("spi:uc1701");
168 MODULE_DESCRIPTION("FB driver for the UC1701 LCD Controller");
169 MODULE_AUTHOR("Juergen Holzmann");
170 MODULE_LICENSE("GPL");