2 * FB driver for the ST7735R LCD Controller
4 * Copyright (C) 2013 Noralf Tronnes
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <video/mipi_display.h>
24 #define DRVNAME "fb_st7735r"
25 #define DEFAULT_GAMMA "0F 1A 0F 18 2F 28 20 22 1F 1B 23 37 00 07 02 10\n" \
26 "0F 1B 0F 17 33 2C 29 2E 30 30 39 3F 00 07 03 10"
28 static int default_init_sequence[] = {
29 -1, MIPI_DCS_SOFT_RESET,
32 -1, MIPI_DCS_EXIT_SLEEP_MODE,
35 /* FRMCTR1 - frame rate control: normal mode
36 frame rate = fosc / (1 x 2 + 40) * (LINE + 2C + 2D) */
37 -1, 0xB1, 0x01, 0x2C, 0x2D,
39 /* FRMCTR2 - frame rate control: idle mode
40 frame rate = fosc / (1 x 2 + 40) * (LINE + 2C + 2D) */
41 -1, 0xB2, 0x01, 0x2C, 0x2D,
43 /* FRMCTR3 - frame rate control - partial mode
44 dot inversion mode, line inversion mode */
45 -1, 0xB3, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D,
47 /* INVCTR - display inversion control
51 /* PWCTR1 - Power Control
53 -1, 0xC0, 0xA2, 0x02, 0x84,
55 /* PWCTR2 - Power Control
56 VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD */
59 /* PWCTR3 - Power Control
60 Opamp current small, Boost frequency */
63 /* PWCTR4 - Power Control
64 BCLK/2, Opamp current small & Medium low */
67 /* PWCTR5 - Power Control */
70 /* VMCTR1 - Power Control */
73 -1, MIPI_DCS_EXIT_INVERT_MODE,
75 -1, MIPI_DCS_SET_PIXEL_FORMAT, MIPI_DCS_PIXEL_FMT_16BIT,
77 -1, MIPI_DCS_SET_DISPLAY_ON,
80 -1, MIPI_DCS_ENTER_NORMAL_MODE,
87 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
89 write_reg(par, MIPI_DCS_SET_COLUMN_ADDRESS,
90 xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
92 write_reg(par, MIPI_DCS_SET_PAGE_ADDRESS,
93 ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
95 write_reg(par, MIPI_DCS_WRITE_MEMORY_START);
101 static int set_var(struct fbtft_par *par)
103 /* MADCTL - Memory data access control
105 1. Mode selection pin SRGB
106 RGB H/W pin for color filter setting: 0=RGB, 1=BGR
108 RGB-BGR ORDER color filter panel: 0=RGB, 1=BGR */
109 switch (par->info->var.rotate) {
111 write_reg(par, MIPI_DCS_SET_ADDRESS_MODE,
112 MX | MY | (par->bgr << 3));
115 write_reg(par, MIPI_DCS_SET_ADDRESS_MODE,
116 MY | MV | (par->bgr << 3));
119 write_reg(par, MIPI_DCS_SET_ADDRESS_MODE,
123 write_reg(par, MIPI_DCS_SET_ADDRESS_MODE,
124 MX | MV | (par->bgr << 3));
133 VRF0P VOS0P PK0P PK1P PK2P PK3P PK4P PK5P PK6P PK7P PK8P PK9P SELV0P SELV1P SELV62P SELV63P
134 VRF0N VOS0N PK0N PK1N PK2N PK3N PK4N PK5N PK6N PK7N PK8N PK9N SELV0N SELV1N SELV62N SELV63N
136 #define CURVE(num, idx) curves[num * par->gamma.num_values + idx]
137 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
142 for (i = 0; i < par->gamma.num_curves; i++)
143 for (j = 0; j < par->gamma.num_values; j++)
146 for (i = 0; i < par->gamma.num_curves; i++)
147 write_reg(par, 0xE0 + i,
148 CURVE(i, 0), CURVE(i, 1), CURVE(i, 2), CURVE(i, 3),
149 CURVE(i, 4), CURVE(i, 5), CURVE(i, 6), CURVE(i, 7),
150 CURVE(i, 8), CURVE(i, 9), CURVE(i, 10), CURVE(i, 11),
151 CURVE(i, 12), CURVE(i, 13), CURVE(i, 14), CURVE(i, 15));
157 static struct fbtft_display display = {
161 .init_sequence = default_init_sequence,
164 .gamma = DEFAULT_GAMMA,
166 .set_addr_win = set_addr_win,
168 .set_gamma = set_gamma,
172 FBTFT_REGISTER_DRIVER(DRVNAME, "sitronix,st7735r", &display);
174 MODULE_ALIAS("spi:" DRVNAME);
175 MODULE_ALIAS("platform:" DRVNAME);
176 MODULE_ALIAS("spi:st7735r");
177 MODULE_ALIAS("platform:st7735r");
179 MODULE_DESCRIPTION("FB driver for the ST7735R LCD Controller");
180 MODULE_AUTHOR("Noralf Tronnes");
181 MODULE_LICENSE("GPL");