-
Notifications
You must be signed in to change notification settings - Fork 1
/
fb_ili9488.c
190 lines (165 loc) · 4.74 KB
/
fb_ili9488.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
* FB driver for the ILI9488 LCD Controller
*
* Copyright (C) 2014 Noralf Tronnes
* Copyright (C) 2019 BIRD TECHSTEP
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* Edit by BIRD TECHSTEP
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/gpio.h>
#include "fbtft.h"
#define DRVNAME "fb_ili9488"
#define WIDTH 320
#define HEIGHT 480
#define BPP 16
#define FPS 60
/* this init sequence matches PiScreen */
static const s16 default_init_sequence[] = {
/* Positive Gamma Control */
-1, 0xE0, 0x00, 0x03, 0x09, 0x08, 0x16, 0x0A, 0x3F, 0x78, 0x4C, 0x09, 0x0A, 0x08, 0x16, 0x1A, 0x0F,
/* Negative Gamma Control */
-1, 0xE1, 0x00, 0x16, 0x19, 0x03, 0x0F, 0x05, 0x32, 0x45, 0x46, 0x04, 0x0E, 0x0D, 0x35, 0x37, 0x0F,
/* Power Control 1 */
-1, 0xC0, 0x17, 0x15,
/* Power Control 2 */
-1, 0xC1, 0x41,
/* VCOM Control */
-1, 0xC5, 0x00, 0x12, 0x80,
/* Memory Access Control */
-1, 0x36, 0x48,
/* Pixel Interface Format 18 bit colour for SPI */
-1, 0x3A, 0x66,
/* Interface Mode Control */
-1, 0xB0, 0x00,
/* Frame Rate Control */
-1, 0xB1, 0xA0,
/* Display Inversion Control */
-1, 0xB4, 0x02,
/* Display Function Control */
-1, 0xB6, 0x02, 0x02, 0x3B,
/* Entry Mode Set */
-1, 0xB7, 0xC6,
/* Adjust Control 3 */
-1, 0xF7, 0xA9, 0x51, 0x2C, 0x82,
/* Exit Sleep */
-1, 0x11,
-2, 120,
/* Display on */
-1, 0x29,
-2, 25,
/* end marker */
-3
};
static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
{
fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
"%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
/* Column address */
write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
/* Row adress */
write_reg(par, 0x2B, ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
/* Memory write */
write_reg(par, 0x2C);
}
/* 16 bit convert to 18 bit pixel over 8-bit databus */
static int write_vmem16_18bus8(struct fbtft_par *par, size_t offset, size_t len)
{
u16 *vmem16;
u8 *txbuf = par->txbuf.buf;
size_t remain;
size_t to_copy;
size_t tx_array_size;
int i;
int ret = 0;
fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n",
__func__, offset, len);
/* remaining number of pixels to send */
remain = len / 2;
vmem16 = (u16 *)(par->info->screen_buffer + offset);
if (par->gpio.dc != -1)
gpio_set_value(par->gpio.dc, 1);
/* number of pixels that fits in the transmit buffer */
tx_array_size = par->txbuf.len / 3;
while (remain) {
/* number of pixels to copy in one iteration of the loop */
to_copy = min(tx_array_size, remain);
dev_dbg(par->info->device, " to_copy=%zu, remain=%zu\n",
to_copy, remain - to_copy);
for (i = 0; i < to_copy; i++) {
u16 pixel = vmem16[i];
u16 b = pixel & 0x1f;
u16 g = (pixel & (0x3f << 5)) >> 5;
u16 r = (pixel & (0x1f << 11)) >> 11;
u8 r8 = (r & 0x1F) << 3;
u8 g8 = (g & 0x3F) << 2;
u8 b8 = (b & 0x1F) << 3;
txbuf[i * 3 + 0] = r8;
txbuf[i * 3 + 1] = g8;
txbuf[i * 3 + 2] = b8;
}
vmem16 = vmem16 + to_copy;
ret = par->fbtftops.write(par, par->txbuf.buf, to_copy * 3);
if (ret < 0)
return ret;
remain -= to_copy;
}
return ret;
}
static int set_var(struct fbtft_par *par)
{
fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
switch (par->info->var.rotate) {
case 0:
write_reg(par, 0x36, 0x80 | (par->bgr << 3));
break;
case 90:
write_reg(par, 0x36, 0x20 | (par->bgr << 3));
break;
case 180:
write_reg(par, 0x36, 0x40 | (par->bgr << 3));
break;
case 270:
write_reg(par, 0x36, 0xE0 | (par->bgr << 3));
break;
default:
break;
}
return 0;
}
static struct fbtft_display display = {
.regwidth = 8,
.width = WIDTH,
.height = HEIGHT,
.bpp = BPP,
.fps = FPS,
.init_sequence = default_init_sequence,
.fbtftops = {
.set_addr_win = set_addr_win,
.set_var = set_var,
.write_vmem = write_vmem16_18bus8,
},
};
FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9488", &display);
MODULE_ALIAS("spi:" DRVNAME);
MODULE_ALIAS("platform:" DRVNAME);
MODULE_ALIAS("spi:ili9488");
MODULE_ALIAS("platform:ili9488");
MODULE_DESCRIPTION("FB driver for the ILI9488 LCD Controller");
MODULE_AUTHOR("BIRD TECHSTEP");
MODULE_LICENSE("GPL");