1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Novatek NT35510 panel driver
4*4882a593Smuzhiyun * Copyright (C) 2020 Linus Walleij <linus.walleij@linaro.org>
5*4882a593Smuzhiyun * Based on code by Robert Teather (C) 2012 Samsung
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * This display driver (and I refer to the physical component NT35510,
8*4882a593Smuzhiyun * not this Linux kernel software driver) can handle:
9*4882a593Smuzhiyun * 480x864, 480x854, 480x800, 480x720 and 480x640 pixel displays.
10*4882a593Smuzhiyun * It has 480x840x24bit SRAM embedded for storing a frame.
11*4882a593Smuzhiyun * When powered on the display is by default in 480x800 mode.
12*4882a593Smuzhiyun *
13*4882a593Smuzhiyun * The actual panels using this component have different names, but
14*4882a593Smuzhiyun * the code needed to set up and configure the panel will be similar,
15*4882a593Smuzhiyun * so they should all use the NT35510 driver with appropriate configuration
16*4882a593Smuzhiyun * per-panel, e.g. for physical size.
17*4882a593Smuzhiyun *
18*4882a593Smuzhiyun * This driver is for the DSI interface to panels using the NT35510.
19*4882a593Smuzhiyun *
20*4882a593Smuzhiyun * The NT35510 can also use an RGB (DPI) interface combined with an
21*4882a593Smuzhiyun * I2C or SPI interface for setting up the NT35510. If this is needed
22*4882a593Smuzhiyun * this panel driver should be refactored to also support that use
23*4882a593Smuzhiyun * case.
24*4882a593Smuzhiyun */
25*4882a593Smuzhiyun #include <linux/backlight.h>
26*4882a593Smuzhiyun #include <linux/bitops.h>
27*4882a593Smuzhiyun #include <linux/gpio/consumer.h>
28*4882a593Smuzhiyun #include <linux/module.h>
29*4882a593Smuzhiyun #include <linux/of_device.h>
30*4882a593Smuzhiyun #include <linux/regmap.h>
31*4882a593Smuzhiyun #include <linux/regulator/consumer.h>
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun #include <video/mipi_display.h>
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun #include <drm/drm_mipi_dsi.h>
36*4882a593Smuzhiyun #include <drm/drm_modes.h>
37*4882a593Smuzhiyun #include <drm/drm_panel.h>
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun #define MCS_CMD_MAUCCTR 0xF0 /* Manufacturer command enable */
40*4882a593Smuzhiyun #define MCS_CMD_READ_ID1 0xDA
41*4882a593Smuzhiyun #define MCS_CMD_READ_ID2 0xDB
42*4882a593Smuzhiyun #define MCS_CMD_READ_ID3 0xDC
43*4882a593Smuzhiyun #define MCS_CMD_MTP_READ_SETTING 0xF8 /* Uncertain about name */
44*4882a593Smuzhiyun #define MCS_CMD_MTP_READ_PARAM 0xFF /* Uncertain about name */
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun /*
47*4882a593Smuzhiyun * These manufacturer commands are available after we enable manufacturer
48*4882a593Smuzhiyun * command set (MCS) for page 0.
49*4882a593Smuzhiyun */
50*4882a593Smuzhiyun #define NT35510_P0_DOPCTR 0xB1
51*4882a593Smuzhiyun #define NT35510_P0_SDHDTCTR 0xB6
52*4882a593Smuzhiyun #define NT35510_P0_GSEQCTR 0xB7
53*4882a593Smuzhiyun #define NT35510_P0_SDEQCTR 0xB8
54*4882a593Smuzhiyun #define NT35510_P0_SDVPCTR 0xBA
55*4882a593Smuzhiyun #define NT35510_P0_DPFRCTR1 0xBD
56*4882a593Smuzhiyun #define NT35510_P0_DPFRCTR2 0xBE
57*4882a593Smuzhiyun #define NT35510_P0_DPFRCTR3 0xBF
58*4882a593Smuzhiyun #define NT35510_P0_DPMCTR12 0xCC
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun #define NT35510_P0_DOPCTR_LEN 2
61*4882a593Smuzhiyun #define NT35510_P0_GSEQCTR_LEN 2
62*4882a593Smuzhiyun #define NT35510_P0_SDEQCTR_LEN 4
63*4882a593Smuzhiyun #define NT35510_P0_SDVPCTR_LEN 1
64*4882a593Smuzhiyun #define NT35510_P0_DPFRCTR1_LEN 5
65*4882a593Smuzhiyun #define NT35510_P0_DPFRCTR2_LEN 5
66*4882a593Smuzhiyun #define NT35510_P0_DPFRCTR3_LEN 5
67*4882a593Smuzhiyun #define NT35510_P0_DPMCTR12_LEN 3
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun #define NT35510_DOPCTR_0_RAMKP BIT(7) /* Contents kept in sleep */
70*4882a593Smuzhiyun #define NT35510_DOPCTR_0_DSITE BIT(6) /* Enable TE signal */
71*4882a593Smuzhiyun #define NT35510_DOPCTR_0_DSIG BIT(5) /* Enable generic read/write */
72*4882a593Smuzhiyun #define NT35510_DOPCTR_0_DSIM BIT(4) /* Enable video mode on DSI */
73*4882a593Smuzhiyun #define NT35510_DOPCTR_0_EOTP BIT(3) /* Support EoTP */
74*4882a593Smuzhiyun #define NT35510_DOPCTR_0_N565 BIT(2) /* RGB or BGR pixel format */
75*4882a593Smuzhiyun #define NT35510_DOPCTR_1_TW_PWR_SEL BIT(4) /* TE power selector */
76*4882a593Smuzhiyun #define NT35510_DOPCTR_1_CRGB BIT(3) /* RGB or BGR byte order */
77*4882a593Smuzhiyun #define NT35510_DOPCTR_1_CTB BIT(2) /* Vertical scanning direction */
78*4882a593Smuzhiyun #define NT35510_DOPCTR_1_CRL BIT(1) /* Source driver data shift */
79*4882a593Smuzhiyun #define NT35510_P0_SDVPCTR_PRG BIT(2) /* 0 = normal operation, 1 = VGLO */
80*4882a593Smuzhiyun #define NT35510_P0_SDVPCTR_AVDD 0 /* source driver output = AVDD */
81*4882a593Smuzhiyun #define NT35510_P0_SDVPCTR_OFFCOL 1 /* source driver output = off color */
82*4882a593Smuzhiyun #define NT35510_P0_SDVPCTR_AVSS 2 /* source driver output = AVSS */
83*4882a593Smuzhiyun #define NT35510_P0_SDVPCTR_HI_Z 3 /* source driver output = High impedance */
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun /*
86*4882a593Smuzhiyun * These manufacturer commands are available after we enable manufacturer
87*4882a593Smuzhiyun * command set (MCS) for page 1.
88*4882a593Smuzhiyun */
89*4882a593Smuzhiyun #define NT35510_P1_SETAVDD 0xB0
90*4882a593Smuzhiyun #define NT35510_P1_SETAVEE 0xB1
91*4882a593Smuzhiyun #define NT35510_P1_SETVCL 0xB2
92*4882a593Smuzhiyun #define NT35510_P1_SETVGH 0xB3
93*4882a593Smuzhiyun #define NT35510_P1_SETVRGH 0xB4
94*4882a593Smuzhiyun #define NT35510_P1_SETVGL 0xB5
95*4882a593Smuzhiyun #define NT35510_P1_BT1CTR 0xB6
96*4882a593Smuzhiyun #define NT35510_P1_BT2CTR 0xB7
97*4882a593Smuzhiyun #define NT35510_P1_BT3CTR 0xB8
98*4882a593Smuzhiyun #define NT35510_P1_BT4CTR 0xB9 /* VGH boosting times/freq */
99*4882a593Smuzhiyun #define NT35510_P1_BT5CTR 0xBA
100*4882a593Smuzhiyun #define NT35510_P1_PFMCTR 0xBB
101*4882a593Smuzhiyun #define NT35510_P1_SETVGP 0xBC
102*4882a593Smuzhiyun #define NT35510_P1_SETVGN 0xBD
103*4882a593Smuzhiyun #define NT35510_P1_SETVCMOFF 0xBE
104*4882a593Smuzhiyun #define NT35510_P1_VGHCTR 0xBF /* VGH output ctrl */
105*4882a593Smuzhiyun #define NT35510_P1_SET_GAMMA_RED_POS 0xD1
106*4882a593Smuzhiyun #define NT35510_P1_SET_GAMMA_GREEN_POS 0xD2
107*4882a593Smuzhiyun #define NT35510_P1_SET_GAMMA_BLUE_POS 0xD3
108*4882a593Smuzhiyun #define NT35510_P1_SET_GAMMA_RED_NEG 0xD4
109*4882a593Smuzhiyun #define NT35510_P1_SET_GAMMA_GREEN_NEG 0xD5
110*4882a593Smuzhiyun #define NT35510_P1_SET_GAMMA_BLUE_NEG 0xD6
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun /* AVDD and AVEE setting 3 bytes */
113*4882a593Smuzhiyun #define NT35510_P1_AVDD_LEN 3
114*4882a593Smuzhiyun #define NT35510_P1_AVEE_LEN 3
115*4882a593Smuzhiyun #define NT35510_P1_VGH_LEN 3
116*4882a593Smuzhiyun #define NT35510_P1_VGL_LEN 3
117*4882a593Smuzhiyun #define NT35510_P1_VGP_LEN 3
118*4882a593Smuzhiyun #define NT35510_P1_VGN_LEN 3
119*4882a593Smuzhiyun /* BT1CTR thru BT5CTR setting 3 bytes */
120*4882a593Smuzhiyun #define NT35510_P1_BT1CTR_LEN 3
121*4882a593Smuzhiyun #define NT35510_P1_BT2CTR_LEN 3
122*4882a593Smuzhiyun #define NT35510_P1_BT4CTR_LEN 3
123*4882a593Smuzhiyun #define NT35510_P1_BT5CTR_LEN 3
124*4882a593Smuzhiyun /* 52 gamma parameters times two per color: positive and negative */
125*4882a593Smuzhiyun #define NT35510_P1_GAMMA_LEN 52
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun /**
128*4882a593Smuzhiyun * struct nt35510_config - the display-specific NT35510 configuration
129*4882a593Smuzhiyun *
130*4882a593Smuzhiyun * Some of the settings provide an array of bytes, A, B C which mean:
131*4882a593Smuzhiyun * A = normal / idle off mode
132*4882a593Smuzhiyun * B = idle on mode
133*4882a593Smuzhiyun * C = partial / idle off mode
134*4882a593Smuzhiyun *
135*4882a593Smuzhiyun * Gamma correction arrays are 10bit numbers, two consecutive bytes
136*4882a593Smuzhiyun * makes out one point on the gamma correction curve. The points are
137*4882a593Smuzhiyun * not linearly placed along the X axis, we get points 0, 1, 3, 5
138*4882a593Smuzhiyun * 7, 11, 15, 23, 31, 47, 63, 95, 127, 128, 160, 192, 208, 224, 232,
139*4882a593Smuzhiyun * 240, 244, 248, 250, 252, 254, 255. The voltages tuples form
140*4882a593Smuzhiyun * V0, V1, V3 ... V255, with 0x0000 being the lowest voltage and
141*4882a593Smuzhiyun * 0x03FF being the highest voltage.
142*4882a593Smuzhiyun *
143*4882a593Smuzhiyun * Each value must be strictly higher than the previous value forming
144*4882a593Smuzhiyun * a rising curve like this:
145*4882a593Smuzhiyun *
146*4882a593Smuzhiyun * ^
147*4882a593Smuzhiyun * | V255
148*4882a593Smuzhiyun * | V254
149*4882a593Smuzhiyun * | ....
150*4882a593Smuzhiyun * | V5
151*4882a593Smuzhiyun * | V3
152*4882a593Smuzhiyun * | V1
153*4882a593Smuzhiyun * | V0
154*4882a593Smuzhiyun * +------------------------------------------->
155*4882a593Smuzhiyun *
156*4882a593Smuzhiyun * The details about all settings can be found in the NT35510 Application
157*4882a593Smuzhiyun * Note.
158*4882a593Smuzhiyun */
159*4882a593Smuzhiyun struct nt35510_config {
160*4882a593Smuzhiyun /**
161*4882a593Smuzhiyun * @width_mm: physical panel width [mm]
162*4882a593Smuzhiyun */
163*4882a593Smuzhiyun u32 width_mm;
164*4882a593Smuzhiyun /**
165*4882a593Smuzhiyun * @height_mm: physical panel height [mm]
166*4882a593Smuzhiyun */
167*4882a593Smuzhiyun u32 height_mm;
168*4882a593Smuzhiyun /**
169*4882a593Smuzhiyun * @mode: the display mode. This is only relevant outside the panel
170*4882a593Smuzhiyun * in video mode: in command mode this is configuring the internal
171*4882a593Smuzhiyun * timing in the display controller.
172*4882a593Smuzhiyun */
173*4882a593Smuzhiyun const struct drm_display_mode mode;
174*4882a593Smuzhiyun /**
175*4882a593Smuzhiyun * @avdd: setting for AVDD ranging from 0x00 = 6.5V to 0x14 = 4.5V
176*4882a593Smuzhiyun * in 0.1V steps the default is 0x05 which means 6.0V
177*4882a593Smuzhiyun */
178*4882a593Smuzhiyun u8 avdd[NT35510_P1_AVDD_LEN];
179*4882a593Smuzhiyun /**
180*4882a593Smuzhiyun * @bt1ctr: setting for boost power control for the AVDD step-up
181*4882a593Smuzhiyun * circuit (1)
182*4882a593Smuzhiyun * bits 0..2 in the lower nibble controls PCK, the booster clock
183*4882a593Smuzhiyun * frequency for the step-up circuit:
184*4882a593Smuzhiyun * 0 = Hsync/32
185*4882a593Smuzhiyun * 1 = Hsync/16
186*4882a593Smuzhiyun * 2 = Hsync/8
187*4882a593Smuzhiyun * 3 = Hsync/4
188*4882a593Smuzhiyun * 4 = Hsync/2
189*4882a593Smuzhiyun * 5 = Hsync
190*4882a593Smuzhiyun * 6 = Hsync x 2
191*4882a593Smuzhiyun * 7 = Hsync x 4
192*4882a593Smuzhiyun * bits 4..6 in the upper nibble controls BTP, the boosting
193*4882a593Smuzhiyun * amplification for the the step-up circuit:
194*4882a593Smuzhiyun * 0 = Disable
195*4882a593Smuzhiyun * 1 = 1.5 x VDDB
196*4882a593Smuzhiyun * 2 = 1.66 x VDDB
197*4882a593Smuzhiyun * 3 = 2 x VDDB
198*4882a593Smuzhiyun * 4 = 2.5 x VDDB
199*4882a593Smuzhiyun * 5 = 3 x VDDB
200*4882a593Smuzhiyun * The defaults are 4 and 4 yielding 0x44
201*4882a593Smuzhiyun */
202*4882a593Smuzhiyun u8 bt1ctr[NT35510_P1_BT1CTR_LEN];
203*4882a593Smuzhiyun /**
204*4882a593Smuzhiyun * @avee: setting for AVEE ranging from 0x00 = -6.5V to 0x14 = -4.5V
205*4882a593Smuzhiyun * in 0.1V steps the default is 0x05 which means -6.0V
206*4882a593Smuzhiyun */
207*4882a593Smuzhiyun u8 avee[NT35510_P1_AVEE_LEN];
208*4882a593Smuzhiyun /**
209*4882a593Smuzhiyun * @bt2ctr: setting for boost power control for the AVEE step-up
210*4882a593Smuzhiyun * circuit (2)
211*4882a593Smuzhiyun * bits 0..2 in the lower nibble controls NCK, the booster clock
212*4882a593Smuzhiyun * frequency, the values are the same as for PCK in @bt1ctr.
213*4882a593Smuzhiyun * bits 4..5 in the upper nibble controls BTN, the boosting
214*4882a593Smuzhiyun * amplification for the the step-up circuit.
215*4882a593Smuzhiyun * 0 = Disable
216*4882a593Smuzhiyun * 1 = -1.5 x VDDB
217*4882a593Smuzhiyun * 2 = -2 x VDDB
218*4882a593Smuzhiyun * 3 = -2.5 x VDDB
219*4882a593Smuzhiyun * 4 = -3 x VDDB
220*4882a593Smuzhiyun * The defaults are 4 and 3 yielding 0x34
221*4882a593Smuzhiyun */
222*4882a593Smuzhiyun u8 bt2ctr[NT35510_P1_BT2CTR_LEN];
223*4882a593Smuzhiyun /**
224*4882a593Smuzhiyun * @vgh: setting for VGH ranging from 0x00 = 7.0V to 0x0B = 18.0V
225*4882a593Smuzhiyun * in 1V steps, the default is 0x08 which means 15V
226*4882a593Smuzhiyun */
227*4882a593Smuzhiyun u8 vgh[NT35510_P1_VGH_LEN];
228*4882a593Smuzhiyun /**
229*4882a593Smuzhiyun * @bt4ctr: setting for boost power control for the VGH step-up
230*4882a593Smuzhiyun * circuit (4)
231*4882a593Smuzhiyun * bits 0..2 in the lower nibble controls HCK, the booster clock
232*4882a593Smuzhiyun * frequency, the values are the same as for PCK in @bt1ctr.
233*4882a593Smuzhiyun * bits 4..5 in the upper nibble controls BTH, the boosting
234*4882a593Smuzhiyun * amplification for the the step-up circuit.
235*4882a593Smuzhiyun * 0 = AVDD + VDDB
236*4882a593Smuzhiyun * 1 = AVDD - AVEE
237*4882a593Smuzhiyun * 2 = AVDD - AVEE + VDDB
238*4882a593Smuzhiyun * 3 = AVDD x 2 - AVEE
239*4882a593Smuzhiyun * The defaults are 4 and 3 yielding 0x34
240*4882a593Smuzhiyun */
241*4882a593Smuzhiyun u8 bt4ctr[NT35510_P1_BT4CTR_LEN];
242*4882a593Smuzhiyun /**
243*4882a593Smuzhiyun * @vgl: setting for VGL ranging from 0x00 = -2V to 0x0f = -15V in
244*4882a593Smuzhiyun * 1V steps, the default is 0x08 which means -10V
245*4882a593Smuzhiyun */
246*4882a593Smuzhiyun u8 vgl[NT35510_P1_VGL_LEN];
247*4882a593Smuzhiyun /**
248*4882a593Smuzhiyun * @bt5ctr: setting for boost power control for the VGL step-up
249*4882a593Smuzhiyun * circuit (5)
250*4882a593Smuzhiyun * bits 0..2 in the lower nibble controls LCK, the booster clock
251*4882a593Smuzhiyun * frequency, the values are the same as for PCK in @bt1ctr.
252*4882a593Smuzhiyun * bits 4..5 in the upper nibble controls BTL, the boosting
253*4882a593Smuzhiyun * amplification for the the step-up circuit.
254*4882a593Smuzhiyun * 0 = AVEE + VCL
255*4882a593Smuzhiyun * 1 = AVEE - AVDD
256*4882a593Smuzhiyun * 2 = AVEE + VCL - AVDD
257*4882a593Smuzhiyun * 3 = AVEE x 2 - AVDD
258*4882a593Smuzhiyun * The defaults are 3 and 2 yielding 0x32
259*4882a593Smuzhiyun */
260*4882a593Smuzhiyun u8 bt5ctr[NT35510_P1_BT5CTR_LEN];
261*4882a593Smuzhiyun /**
262*4882a593Smuzhiyun * @vgp: setting for VGP, the positive gamma divider voltages
263*4882a593Smuzhiyun * VGMP the high voltage and VGSP the low voltage.
264*4882a593Smuzhiyun * The first byte contains bit 8 of VGMP and VGSP in bits 4 and 0
265*4882a593Smuzhiyun * The second byte contains bit 0..7 of VGMP
266*4882a593Smuzhiyun * The third byte contains bit 0..7 of VGSP
267*4882a593Smuzhiyun * VGMP 0x00 = 3.0V .. 0x108 = 6.3V in steps of 12.5mV
268*4882a593Smuzhiyun * VGSP 0x00 = 0V .. 0x111 = 3.7V in steps of 12.5mV
269*4882a593Smuzhiyun */
270*4882a593Smuzhiyun u8 vgp[NT35510_P1_VGP_LEN];
271*4882a593Smuzhiyun /**
272*4882a593Smuzhiyun * @vgn: setting for VGN, the negative gamma divider voltages,
273*4882a593Smuzhiyun * same layout of bytes as @vgp.
274*4882a593Smuzhiyun */
275*4882a593Smuzhiyun u8 vgn[NT35510_P1_VGN_LEN];
276*4882a593Smuzhiyun /**
277*4882a593Smuzhiyun * @sdeqctr: Source driver control settings, first byte is
278*4882a593Smuzhiyun * 0 for mode 1 and 1 for mode 2. Mode 1 uses two steps and
279*4882a593Smuzhiyun * mode 2 uses three steps meaning EQS3 is not used in mode
280*4882a593Smuzhiyun * 1. Mode 2 is default. The last three parameters are EQS1, EQS2
281*4882a593Smuzhiyun * and EQS3, setting the rise time for each equalizer step:
282*4882a593Smuzhiyun * 0x00 = 0.0 us to 0x0f = 7.5 us in steps of 0.5us. The default
283*4882a593Smuzhiyun * is 0x07 = 3.5 us.
284*4882a593Smuzhiyun */
285*4882a593Smuzhiyun u8 sdeqctr[NT35510_P0_SDEQCTR_LEN];
286*4882a593Smuzhiyun /**
287*4882a593Smuzhiyun * @sdvpctr: power/voltage behaviour during vertical porch time
288*4882a593Smuzhiyun */
289*4882a593Smuzhiyun u8 sdvpctr;
290*4882a593Smuzhiyun /**
291*4882a593Smuzhiyun * @t1: the number of pixel clocks on one scanline, range
292*4882a593Smuzhiyun * 0x100 (258 ticks) .. 0x3FF (1024 ticks) so the value + 1
293*4882a593Smuzhiyun * clock ticks.
294*4882a593Smuzhiyun */
295*4882a593Smuzhiyun u16 t1;
296*4882a593Smuzhiyun /**
297*4882a593Smuzhiyun * @vbp: vertical back porch toward the PANEL note: not toward
298*4882a593Smuzhiyun * the DSI host; these are separate interfaces, in from DSI host
299*4882a593Smuzhiyun * and out to the panel.
300*4882a593Smuzhiyun */
301*4882a593Smuzhiyun u8 vbp;
302*4882a593Smuzhiyun /**
303*4882a593Smuzhiyun * @vfp: vertical front porch toward the PANEL.
304*4882a593Smuzhiyun */
305*4882a593Smuzhiyun u8 vfp;
306*4882a593Smuzhiyun /**
307*4882a593Smuzhiyun * @psel: pixel clock divisor: 0 = 1, 1 = 2, 2 = 4, 3 = 8.
308*4882a593Smuzhiyun */
309*4882a593Smuzhiyun u8 psel;
310*4882a593Smuzhiyun /**
311*4882a593Smuzhiyun * @dpmctr12: Display timing control 12
312*4882a593Smuzhiyun * Byte 1 bit 4 selects LVGL voltage level: 0 = VGLX, 1 = VGL_REG
313*4882a593Smuzhiyun * Byte 1 bit 1 selects gate signal mode: 0 = non-overlap, 1 = overlap
314*4882a593Smuzhiyun * Byte 1 bit 0 selects output signal control R/L swap, 0 = normal
315*4882a593Smuzhiyun * 1 = swap all O->E, L->R
316*4882a593Smuzhiyun * Byte 2 is CLW delay clock for CK O/E and CKB O/E signals:
317*4882a593Smuzhiyun * 0x00 = 0us .. 0xFF = 12.75us in 0.05us steps
318*4882a593Smuzhiyun * Byte 3 is FTI_H0 delay time for STP O/E signals:
319*4882a593Smuzhiyun * 0x00 = 0us .. 0xFF = 12.75us in 0.05us steps
320*4882a593Smuzhiyun */
321*4882a593Smuzhiyun u8 dpmctr12[NT35510_P0_DPMCTR12_LEN];
322*4882a593Smuzhiyun /**
323*4882a593Smuzhiyun * @gamma_corr_pos_r: Red gamma correction parameters, positive
324*4882a593Smuzhiyun */
325*4882a593Smuzhiyun u8 gamma_corr_pos_r[NT35510_P1_GAMMA_LEN];
326*4882a593Smuzhiyun /**
327*4882a593Smuzhiyun * @gamma_corr_pos_g: Green gamma correction parameters, positive
328*4882a593Smuzhiyun */
329*4882a593Smuzhiyun u8 gamma_corr_pos_g[NT35510_P1_GAMMA_LEN];
330*4882a593Smuzhiyun /**
331*4882a593Smuzhiyun * @gamma_corr_pos_b: Blue gamma correction parameters, positive
332*4882a593Smuzhiyun */
333*4882a593Smuzhiyun u8 gamma_corr_pos_b[NT35510_P1_GAMMA_LEN];
334*4882a593Smuzhiyun /**
335*4882a593Smuzhiyun * @gamma_corr_neg_r: Red gamma correction parameters, negative
336*4882a593Smuzhiyun */
337*4882a593Smuzhiyun u8 gamma_corr_neg_r[NT35510_P1_GAMMA_LEN];
338*4882a593Smuzhiyun /**
339*4882a593Smuzhiyun * @gamma_corr_neg_g: Green gamma correction parameters, negative
340*4882a593Smuzhiyun */
341*4882a593Smuzhiyun u8 gamma_corr_neg_g[NT35510_P1_GAMMA_LEN];
342*4882a593Smuzhiyun /**
343*4882a593Smuzhiyun * @gamma_corr_neg_b: Blue gamma correction parameters, negative
344*4882a593Smuzhiyun */
345*4882a593Smuzhiyun u8 gamma_corr_neg_b[NT35510_P1_GAMMA_LEN];
346*4882a593Smuzhiyun };
347*4882a593Smuzhiyun
348*4882a593Smuzhiyun /**
349*4882a593Smuzhiyun * struct nt35510 - state container for the NT35510 panel
350*4882a593Smuzhiyun */
351*4882a593Smuzhiyun struct nt35510 {
352*4882a593Smuzhiyun /**
353*4882a593Smuzhiyun * @dev: the container device
354*4882a593Smuzhiyun */
355*4882a593Smuzhiyun struct device *dev;
356*4882a593Smuzhiyun /**
357*4882a593Smuzhiyun * @conf: the specific panel configuration, as the NT35510
358*4882a593Smuzhiyun * can be combined with many physical panels, they can have
359*4882a593Smuzhiyun * different physical dimensions and gamma correction etc,
360*4882a593Smuzhiyun * so this is stored in the config.
361*4882a593Smuzhiyun */
362*4882a593Smuzhiyun const struct nt35510_config *conf;
363*4882a593Smuzhiyun /**
364*4882a593Smuzhiyun * @panel: the DRM panel object for the instance
365*4882a593Smuzhiyun */
366*4882a593Smuzhiyun struct drm_panel panel;
367*4882a593Smuzhiyun /**
368*4882a593Smuzhiyun * @supplies: regulators supplying the panel
369*4882a593Smuzhiyun */
370*4882a593Smuzhiyun struct regulator_bulk_data supplies[2];
371*4882a593Smuzhiyun /**
372*4882a593Smuzhiyun * @reset_gpio: the reset line
373*4882a593Smuzhiyun */
374*4882a593Smuzhiyun struct gpio_desc *reset_gpio;
375*4882a593Smuzhiyun };
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun /* Manufacturer command has strictly this byte sequence */
378*4882a593Smuzhiyun static const u8 nt35510_mauc_mtp_read_param[] = { 0xAA, 0x55, 0x25, 0x01 };
379*4882a593Smuzhiyun static const u8 nt35510_mauc_mtp_read_setting[] = { 0x01, 0x02, 0x00, 0x20,
380*4882a593Smuzhiyun 0x33, 0x13, 0x00, 0x40,
381*4882a593Smuzhiyun 0x00, 0x00, 0x23, 0x02 };
382*4882a593Smuzhiyun static const u8 nt35510_mauc_select_page_0[] = { 0x55, 0xAA, 0x52, 0x08, 0x00 };
383*4882a593Smuzhiyun static const u8 nt35510_mauc_select_page_1[] = { 0x55, 0xAA, 0x52, 0x08, 0x01 };
384*4882a593Smuzhiyun static const u8 nt35510_vgh_on[] = { 0x01 };
385*4882a593Smuzhiyun
panel_to_nt35510(struct drm_panel * panel)386*4882a593Smuzhiyun static inline struct nt35510 *panel_to_nt35510(struct drm_panel *panel)
387*4882a593Smuzhiyun {
388*4882a593Smuzhiyun return container_of(panel, struct nt35510, panel);
389*4882a593Smuzhiyun }
390*4882a593Smuzhiyun
391*4882a593Smuzhiyun #define NT35510_ROTATE_0_SETTING 0x02
392*4882a593Smuzhiyun #define NT35510_ROTATE_180_SETTING 0x00
393*4882a593Smuzhiyun
nt35510_send_long(struct nt35510 * nt,struct mipi_dsi_device * dsi,u8 cmd,u8 cmdlen,const u8 * seq)394*4882a593Smuzhiyun static int nt35510_send_long(struct nt35510 *nt, struct mipi_dsi_device *dsi,
395*4882a593Smuzhiyun u8 cmd, u8 cmdlen, const u8 *seq)
396*4882a593Smuzhiyun {
397*4882a593Smuzhiyun const u8 *seqp = seq;
398*4882a593Smuzhiyun int cmdwritten = 0;
399*4882a593Smuzhiyun int chunk = cmdlen;
400*4882a593Smuzhiyun int ret;
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun if (chunk > 15)
403*4882a593Smuzhiyun chunk = 15;
404*4882a593Smuzhiyun ret = mipi_dsi_dcs_write(dsi, cmd, seqp, chunk);
405*4882a593Smuzhiyun if (ret < 0) {
406*4882a593Smuzhiyun dev_err(nt->dev, "error sending DCS command seq cmd %02x\n", cmd);
407*4882a593Smuzhiyun return ret;
408*4882a593Smuzhiyun }
409*4882a593Smuzhiyun cmdwritten += chunk;
410*4882a593Smuzhiyun seqp += chunk;
411*4882a593Smuzhiyun
412*4882a593Smuzhiyun while (cmdwritten < cmdlen) {
413*4882a593Smuzhiyun chunk = cmdlen - cmdwritten;
414*4882a593Smuzhiyun if (chunk > 15)
415*4882a593Smuzhiyun chunk = 15;
416*4882a593Smuzhiyun ret = mipi_dsi_generic_write(dsi, seqp, chunk);
417*4882a593Smuzhiyun if (ret < 0) {
418*4882a593Smuzhiyun dev_err(nt->dev, "error sending generic write seq %02x\n", cmd);
419*4882a593Smuzhiyun return ret;
420*4882a593Smuzhiyun }
421*4882a593Smuzhiyun cmdwritten += chunk;
422*4882a593Smuzhiyun seqp += chunk;
423*4882a593Smuzhiyun }
424*4882a593Smuzhiyun dev_dbg(nt->dev, "sent command %02x %02x bytes\n", cmd, cmdlen);
425*4882a593Smuzhiyun return 0;
426*4882a593Smuzhiyun }
427*4882a593Smuzhiyun
nt35510_read_id(struct nt35510 * nt)428*4882a593Smuzhiyun static int nt35510_read_id(struct nt35510 *nt)
429*4882a593Smuzhiyun {
430*4882a593Smuzhiyun struct mipi_dsi_device *dsi = to_mipi_dsi_device(nt->dev);
431*4882a593Smuzhiyun u8 id1, id2, id3;
432*4882a593Smuzhiyun int ret;
433*4882a593Smuzhiyun
434*4882a593Smuzhiyun ret = mipi_dsi_dcs_read(dsi, MCS_CMD_READ_ID1, &id1, 1);
435*4882a593Smuzhiyun if (ret < 0) {
436*4882a593Smuzhiyun dev_err(nt->dev, "could not read MTP ID1\n");
437*4882a593Smuzhiyun return ret;
438*4882a593Smuzhiyun }
439*4882a593Smuzhiyun ret = mipi_dsi_dcs_read(dsi, MCS_CMD_READ_ID2, &id2, 1);
440*4882a593Smuzhiyun if (ret < 0) {
441*4882a593Smuzhiyun dev_err(nt->dev, "could not read MTP ID2\n");
442*4882a593Smuzhiyun return ret;
443*4882a593Smuzhiyun }
444*4882a593Smuzhiyun ret = mipi_dsi_dcs_read(dsi, MCS_CMD_READ_ID3, &id3, 1);
445*4882a593Smuzhiyun if (ret < 0) {
446*4882a593Smuzhiyun dev_err(nt->dev, "could not read MTP ID3\n");
447*4882a593Smuzhiyun return ret;
448*4882a593Smuzhiyun }
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun /*
451*4882a593Smuzhiyun * Multi-Time Programmable (?) memory contains manufacturer
452*4882a593Smuzhiyun * ID (e.g. Hydis 0x55), driver ID (e.g. NT35510 0xc0) and
453*4882a593Smuzhiyun * version.
454*4882a593Smuzhiyun */
455*4882a593Smuzhiyun dev_info(nt->dev, "MTP ID manufacturer: %02x version: %02x driver: %02x\n", id1, id2, id3);
456*4882a593Smuzhiyun
457*4882a593Smuzhiyun return 0;
458*4882a593Smuzhiyun }
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun /**
461*4882a593Smuzhiyun * nt35510_setup_power() - set up power config in page 1
462*4882a593Smuzhiyun * @nt: the display instance to set up
463*4882a593Smuzhiyun */
nt35510_setup_power(struct nt35510 * nt)464*4882a593Smuzhiyun static int nt35510_setup_power(struct nt35510 *nt)
465*4882a593Smuzhiyun {
466*4882a593Smuzhiyun struct mipi_dsi_device *dsi = to_mipi_dsi_device(nt->dev);
467*4882a593Smuzhiyun int ret;
468*4882a593Smuzhiyun
469*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_SETAVDD,
470*4882a593Smuzhiyun NT35510_P1_AVDD_LEN,
471*4882a593Smuzhiyun nt->conf->avdd);
472*4882a593Smuzhiyun if (ret)
473*4882a593Smuzhiyun return ret;
474*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_BT1CTR,
475*4882a593Smuzhiyun NT35510_P1_BT1CTR_LEN,
476*4882a593Smuzhiyun nt->conf->bt1ctr);
477*4882a593Smuzhiyun if (ret)
478*4882a593Smuzhiyun return ret;
479*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_SETAVEE,
480*4882a593Smuzhiyun NT35510_P1_AVEE_LEN,
481*4882a593Smuzhiyun nt->conf->avee);
482*4882a593Smuzhiyun if (ret)
483*4882a593Smuzhiyun return ret;
484*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_BT2CTR,
485*4882a593Smuzhiyun NT35510_P1_BT2CTR_LEN,
486*4882a593Smuzhiyun nt->conf->bt2ctr);
487*4882a593Smuzhiyun if (ret)
488*4882a593Smuzhiyun return ret;
489*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_SETVGH,
490*4882a593Smuzhiyun NT35510_P1_VGH_LEN,
491*4882a593Smuzhiyun nt->conf->vgh);
492*4882a593Smuzhiyun if (ret)
493*4882a593Smuzhiyun return ret;
494*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_BT4CTR,
495*4882a593Smuzhiyun NT35510_P1_BT4CTR_LEN,
496*4882a593Smuzhiyun nt->conf->bt4ctr);
497*4882a593Smuzhiyun if (ret)
498*4882a593Smuzhiyun return ret;
499*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_VGHCTR,
500*4882a593Smuzhiyun ARRAY_SIZE(nt35510_vgh_on),
501*4882a593Smuzhiyun nt35510_vgh_on);
502*4882a593Smuzhiyun if (ret)
503*4882a593Smuzhiyun return ret;
504*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_SETVGL,
505*4882a593Smuzhiyun NT35510_P1_VGL_LEN,
506*4882a593Smuzhiyun nt->conf->vgl);
507*4882a593Smuzhiyun if (ret)
508*4882a593Smuzhiyun return ret;
509*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_BT5CTR,
510*4882a593Smuzhiyun NT35510_P1_BT5CTR_LEN,
511*4882a593Smuzhiyun nt->conf->bt5ctr);
512*4882a593Smuzhiyun if (ret)
513*4882a593Smuzhiyun return ret;
514*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_SETVGP,
515*4882a593Smuzhiyun NT35510_P1_VGP_LEN,
516*4882a593Smuzhiyun nt->conf->vgp);
517*4882a593Smuzhiyun if (ret)
518*4882a593Smuzhiyun return ret;
519*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_SETVGN,
520*4882a593Smuzhiyun NT35510_P1_VGN_LEN,
521*4882a593Smuzhiyun nt->conf->vgn);
522*4882a593Smuzhiyun if (ret)
523*4882a593Smuzhiyun return ret;
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun /* Typically 10 ms */
526*4882a593Smuzhiyun usleep_range(10000, 20000);
527*4882a593Smuzhiyun
528*4882a593Smuzhiyun return 0;
529*4882a593Smuzhiyun }
530*4882a593Smuzhiyun
531*4882a593Smuzhiyun /**
532*4882a593Smuzhiyun * nt35510_setup_display() - set up display config in page 0
533*4882a593Smuzhiyun * @nt: the display instance to set up
534*4882a593Smuzhiyun */
nt35510_setup_display(struct nt35510 * nt)535*4882a593Smuzhiyun static int nt35510_setup_display(struct nt35510 *nt)
536*4882a593Smuzhiyun {
537*4882a593Smuzhiyun struct mipi_dsi_device *dsi = to_mipi_dsi_device(nt->dev);
538*4882a593Smuzhiyun const struct nt35510_config *conf = nt->conf;
539*4882a593Smuzhiyun u8 dopctr[NT35510_P0_DOPCTR_LEN];
540*4882a593Smuzhiyun u8 gseqctr[NT35510_P0_GSEQCTR_LEN];
541*4882a593Smuzhiyun u8 dpfrctr[NT35510_P0_DPFRCTR1_LEN];
542*4882a593Smuzhiyun /* FIXME: set up any rotation (assume none for now) */
543*4882a593Smuzhiyun u8 addr_mode = NT35510_ROTATE_0_SETTING;
544*4882a593Smuzhiyun u8 val;
545*4882a593Smuzhiyun int ret;
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun /* Enable TE, EoTP and RGB pixel format */
548*4882a593Smuzhiyun dopctr[0] = NT35510_DOPCTR_0_DSITE | NT35510_DOPCTR_0_EOTP |
549*4882a593Smuzhiyun NT35510_DOPCTR_0_N565;
550*4882a593Smuzhiyun dopctr[1] = NT35510_DOPCTR_1_CTB;
551*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P0_DOPCTR,
552*4882a593Smuzhiyun NT35510_P0_DOPCTR_LEN,
553*4882a593Smuzhiyun dopctr);
554*4882a593Smuzhiyun if (ret)
555*4882a593Smuzhiyun return ret;
556*4882a593Smuzhiyun
557*4882a593Smuzhiyun ret = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_ADDRESS_MODE, &addr_mode,
558*4882a593Smuzhiyun sizeof(addr_mode));
559*4882a593Smuzhiyun if (ret < 0)
560*4882a593Smuzhiyun return ret;
561*4882a593Smuzhiyun
562*4882a593Smuzhiyun /*
563*4882a593Smuzhiyun * Source data hold time, default 0x05 = 2.5us
564*4882a593Smuzhiyun * 0x00..0x3F = 0 .. 31.5us in steps of 0.5us
565*4882a593Smuzhiyun * 0x0A = 5us
566*4882a593Smuzhiyun */
567*4882a593Smuzhiyun val = 0x0A;
568*4882a593Smuzhiyun ret = mipi_dsi_dcs_write(dsi, NT35510_P0_SDHDTCTR, &val,
569*4882a593Smuzhiyun sizeof(val));
570*4882a593Smuzhiyun if (ret < 0)
571*4882a593Smuzhiyun return ret;
572*4882a593Smuzhiyun
573*4882a593Smuzhiyun /* EQ control for gate signals, 0x00 = 0 us */
574*4882a593Smuzhiyun gseqctr[0] = 0x00;
575*4882a593Smuzhiyun gseqctr[1] = 0x00;
576*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P0_GSEQCTR,
577*4882a593Smuzhiyun NT35510_P0_GSEQCTR_LEN,
578*4882a593Smuzhiyun gseqctr);
579*4882a593Smuzhiyun if (ret)
580*4882a593Smuzhiyun return ret;
581*4882a593Smuzhiyun
582*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P0_SDEQCTR,
583*4882a593Smuzhiyun NT35510_P0_SDEQCTR_LEN,
584*4882a593Smuzhiyun conf->sdeqctr);
585*4882a593Smuzhiyun if (ret)
586*4882a593Smuzhiyun return ret;
587*4882a593Smuzhiyun
588*4882a593Smuzhiyun ret = mipi_dsi_dcs_write(dsi, NT35510_P0_SDVPCTR,
589*4882a593Smuzhiyun &conf->sdvpctr, 1);
590*4882a593Smuzhiyun if (ret < 0)
591*4882a593Smuzhiyun return ret;
592*4882a593Smuzhiyun
593*4882a593Smuzhiyun /*
594*4882a593Smuzhiyun * Display timing control for active and idle off mode:
595*4882a593Smuzhiyun * the first byte contains
596*4882a593Smuzhiyun * the two high bits of T1A and second byte the low 8 bits, and
597*4882a593Smuzhiyun * the valid range is 0x100 (257) to 0x3ff (1023) representing
598*4882a593Smuzhiyun * 258..1024 (+1) pixel clock ticks for one scanline. At 20MHz pixel
599*4882a593Smuzhiyun * clock this covers the range of 12.90us .. 51.20us in steps of
600*4882a593Smuzhiyun * 0.05us, the default is 0x184 (388) representing 389 ticks.
601*4882a593Smuzhiyun * The third byte is VBPDA, vertical back porch display active
602*4882a593Smuzhiyun * and the fourth VFPDA, vertical front porch display active,
603*4882a593Smuzhiyun * both given in number of scanlines in the range 0x02..0xff
604*4882a593Smuzhiyun * for 2..255 scanlines. The fifth byte is 2 bits selecting
605*4882a593Smuzhiyun * PSEL for active and idle off mode, how much the 20MHz clock
606*4882a593Smuzhiyun * is divided by 0..3. This needs to be adjusted to get the right
607*4882a593Smuzhiyun * frame rate.
608*4882a593Smuzhiyun */
609*4882a593Smuzhiyun dpfrctr[0] = (conf->t1 >> 8) & 0xFF;
610*4882a593Smuzhiyun dpfrctr[1] = conf->t1 & 0xFF;
611*4882a593Smuzhiyun /* Vertical back porch */
612*4882a593Smuzhiyun dpfrctr[2] = conf->vbp;
613*4882a593Smuzhiyun /* Vertical front porch */
614*4882a593Smuzhiyun dpfrctr[3] = conf->vfp;
615*4882a593Smuzhiyun dpfrctr[4] = conf->psel;
616*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P0_DPFRCTR1,
617*4882a593Smuzhiyun NT35510_P0_DPFRCTR1_LEN,
618*4882a593Smuzhiyun dpfrctr);
619*4882a593Smuzhiyun if (ret)
620*4882a593Smuzhiyun return ret;
621*4882a593Smuzhiyun /* For idle and partial idle off mode we decrease front porch by one */
622*4882a593Smuzhiyun dpfrctr[3]--;
623*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P0_DPFRCTR2,
624*4882a593Smuzhiyun NT35510_P0_DPFRCTR2_LEN,
625*4882a593Smuzhiyun dpfrctr);
626*4882a593Smuzhiyun if (ret)
627*4882a593Smuzhiyun return ret;
628*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P0_DPFRCTR3,
629*4882a593Smuzhiyun NT35510_P0_DPFRCTR3_LEN,
630*4882a593Smuzhiyun dpfrctr);
631*4882a593Smuzhiyun if (ret)
632*4882a593Smuzhiyun return ret;
633*4882a593Smuzhiyun
634*4882a593Smuzhiyun /* Enable TE on vblank */
635*4882a593Smuzhiyun ret = mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
636*4882a593Smuzhiyun if (ret)
637*4882a593Smuzhiyun return ret;
638*4882a593Smuzhiyun
639*4882a593Smuzhiyun /* Turn on the pads? */
640*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P0_DPMCTR12,
641*4882a593Smuzhiyun NT35510_P0_DPMCTR12_LEN,
642*4882a593Smuzhiyun conf->dpmctr12);
643*4882a593Smuzhiyun if (ret)
644*4882a593Smuzhiyun return ret;
645*4882a593Smuzhiyun
646*4882a593Smuzhiyun return 0;
647*4882a593Smuzhiyun }
648*4882a593Smuzhiyun
nt35510_set_brightness(struct backlight_device * bl)649*4882a593Smuzhiyun static int nt35510_set_brightness(struct backlight_device *bl)
650*4882a593Smuzhiyun {
651*4882a593Smuzhiyun struct nt35510 *nt = bl_get_data(bl);
652*4882a593Smuzhiyun struct mipi_dsi_device *dsi = to_mipi_dsi_device(nt->dev);
653*4882a593Smuzhiyun u8 brightness = bl->props.brightness;
654*4882a593Smuzhiyun int ret;
655*4882a593Smuzhiyun
656*4882a593Smuzhiyun dev_dbg(nt->dev, "set brightness %d\n", brightness);
657*4882a593Smuzhiyun ret = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_BRIGHTNESS,
658*4882a593Smuzhiyun &brightness,
659*4882a593Smuzhiyun sizeof(brightness));
660*4882a593Smuzhiyun if (ret < 0)
661*4882a593Smuzhiyun return ret;
662*4882a593Smuzhiyun
663*4882a593Smuzhiyun return 0;
664*4882a593Smuzhiyun }
665*4882a593Smuzhiyun
666*4882a593Smuzhiyun static const struct backlight_ops nt35510_bl_ops = {
667*4882a593Smuzhiyun .update_status = nt35510_set_brightness,
668*4882a593Smuzhiyun };
669*4882a593Smuzhiyun
670*4882a593Smuzhiyun /*
671*4882a593Smuzhiyun * This power-on sequence
672*4882a593Smuzhiyun */
nt35510_power_on(struct nt35510 * nt)673*4882a593Smuzhiyun static int nt35510_power_on(struct nt35510 *nt)
674*4882a593Smuzhiyun {
675*4882a593Smuzhiyun struct mipi_dsi_device *dsi = to_mipi_dsi_device(nt->dev);
676*4882a593Smuzhiyun int ret;
677*4882a593Smuzhiyun
678*4882a593Smuzhiyun ret = regulator_bulk_enable(ARRAY_SIZE(nt->supplies), nt->supplies);
679*4882a593Smuzhiyun if (ret < 0) {
680*4882a593Smuzhiyun dev_err(nt->dev, "unable to enable regulators\n");
681*4882a593Smuzhiyun return ret;
682*4882a593Smuzhiyun }
683*4882a593Smuzhiyun
684*4882a593Smuzhiyun /* Toggle RESET in accordance with datasheet page 370 */
685*4882a593Smuzhiyun if (nt->reset_gpio) {
686*4882a593Smuzhiyun gpiod_set_value(nt->reset_gpio, 1);
687*4882a593Smuzhiyun /* Active min 10 us according to datasheet, let's say 20 */
688*4882a593Smuzhiyun usleep_range(20, 1000);
689*4882a593Smuzhiyun gpiod_set_value(nt->reset_gpio, 0);
690*4882a593Smuzhiyun /*
691*4882a593Smuzhiyun * 5 ms during sleep mode, 120 ms during sleep out mode
692*4882a593Smuzhiyun * according to datasheet, let's use 120-140 ms.
693*4882a593Smuzhiyun */
694*4882a593Smuzhiyun usleep_range(120000, 140000);
695*4882a593Smuzhiyun }
696*4882a593Smuzhiyun
697*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, MCS_CMD_MTP_READ_PARAM,
698*4882a593Smuzhiyun ARRAY_SIZE(nt35510_mauc_mtp_read_param),
699*4882a593Smuzhiyun nt35510_mauc_mtp_read_param);
700*4882a593Smuzhiyun if (ret)
701*4882a593Smuzhiyun return ret;
702*4882a593Smuzhiyun
703*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, MCS_CMD_MTP_READ_SETTING,
704*4882a593Smuzhiyun ARRAY_SIZE(nt35510_mauc_mtp_read_setting),
705*4882a593Smuzhiyun nt35510_mauc_mtp_read_setting);
706*4882a593Smuzhiyun if (ret)
707*4882a593Smuzhiyun return ret;
708*4882a593Smuzhiyun
709*4882a593Smuzhiyun nt35510_read_id(nt);
710*4882a593Smuzhiyun
711*4882a593Smuzhiyun /* Set up stuff in manufacturer control, page 1 */
712*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, MCS_CMD_MAUCCTR,
713*4882a593Smuzhiyun ARRAY_SIZE(nt35510_mauc_select_page_1),
714*4882a593Smuzhiyun nt35510_mauc_select_page_1);
715*4882a593Smuzhiyun if (ret)
716*4882a593Smuzhiyun return ret;
717*4882a593Smuzhiyun
718*4882a593Smuzhiyun ret = nt35510_setup_power(nt);
719*4882a593Smuzhiyun if (ret)
720*4882a593Smuzhiyun return ret;
721*4882a593Smuzhiyun
722*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_SET_GAMMA_RED_POS,
723*4882a593Smuzhiyun NT35510_P1_GAMMA_LEN,
724*4882a593Smuzhiyun nt->conf->gamma_corr_pos_r);
725*4882a593Smuzhiyun if (ret)
726*4882a593Smuzhiyun return ret;
727*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_SET_GAMMA_GREEN_POS,
728*4882a593Smuzhiyun NT35510_P1_GAMMA_LEN,
729*4882a593Smuzhiyun nt->conf->gamma_corr_pos_g);
730*4882a593Smuzhiyun if (ret)
731*4882a593Smuzhiyun return ret;
732*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_SET_GAMMA_BLUE_POS,
733*4882a593Smuzhiyun NT35510_P1_GAMMA_LEN,
734*4882a593Smuzhiyun nt->conf->gamma_corr_pos_b);
735*4882a593Smuzhiyun if (ret)
736*4882a593Smuzhiyun return ret;
737*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_SET_GAMMA_RED_NEG,
738*4882a593Smuzhiyun NT35510_P1_GAMMA_LEN,
739*4882a593Smuzhiyun nt->conf->gamma_corr_neg_r);
740*4882a593Smuzhiyun if (ret)
741*4882a593Smuzhiyun return ret;
742*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_SET_GAMMA_GREEN_NEG,
743*4882a593Smuzhiyun NT35510_P1_GAMMA_LEN,
744*4882a593Smuzhiyun nt->conf->gamma_corr_neg_g);
745*4882a593Smuzhiyun if (ret)
746*4882a593Smuzhiyun return ret;
747*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, NT35510_P1_SET_GAMMA_BLUE_NEG,
748*4882a593Smuzhiyun NT35510_P1_GAMMA_LEN,
749*4882a593Smuzhiyun nt->conf->gamma_corr_neg_b);
750*4882a593Smuzhiyun if (ret)
751*4882a593Smuzhiyun return ret;
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun /* Set up stuff in manufacturer control, page 0 */
754*4882a593Smuzhiyun ret = nt35510_send_long(nt, dsi, MCS_CMD_MAUCCTR,
755*4882a593Smuzhiyun ARRAY_SIZE(nt35510_mauc_select_page_0),
756*4882a593Smuzhiyun nt35510_mauc_select_page_0);
757*4882a593Smuzhiyun if (ret)
758*4882a593Smuzhiyun return ret;
759*4882a593Smuzhiyun
760*4882a593Smuzhiyun ret = nt35510_setup_display(nt);
761*4882a593Smuzhiyun if (ret)
762*4882a593Smuzhiyun return ret;
763*4882a593Smuzhiyun
764*4882a593Smuzhiyun return 0;
765*4882a593Smuzhiyun }
766*4882a593Smuzhiyun
nt35510_power_off(struct nt35510 * nt)767*4882a593Smuzhiyun static int nt35510_power_off(struct nt35510 *nt)
768*4882a593Smuzhiyun {
769*4882a593Smuzhiyun int ret;
770*4882a593Smuzhiyun
771*4882a593Smuzhiyun ret = regulator_bulk_disable(ARRAY_SIZE(nt->supplies), nt->supplies);
772*4882a593Smuzhiyun if (ret)
773*4882a593Smuzhiyun return ret;
774*4882a593Smuzhiyun
775*4882a593Smuzhiyun if (nt->reset_gpio)
776*4882a593Smuzhiyun gpiod_set_value(nt->reset_gpio, 1);
777*4882a593Smuzhiyun
778*4882a593Smuzhiyun return 0;
779*4882a593Smuzhiyun }
780*4882a593Smuzhiyun
nt35510_unprepare(struct drm_panel * panel)781*4882a593Smuzhiyun static int nt35510_unprepare(struct drm_panel *panel)
782*4882a593Smuzhiyun {
783*4882a593Smuzhiyun struct nt35510 *nt = panel_to_nt35510(panel);
784*4882a593Smuzhiyun struct mipi_dsi_device *dsi = to_mipi_dsi_device(nt->dev);
785*4882a593Smuzhiyun int ret;
786*4882a593Smuzhiyun
787*4882a593Smuzhiyun ret = mipi_dsi_dcs_set_display_off(dsi);
788*4882a593Smuzhiyun if (ret) {
789*4882a593Smuzhiyun dev_err(nt->dev, "failed to turn display off (%d)\n", ret);
790*4882a593Smuzhiyun return ret;
791*4882a593Smuzhiyun }
792*4882a593Smuzhiyun usleep_range(10000, 20000);
793*4882a593Smuzhiyun
794*4882a593Smuzhiyun /* Enter sleep mode */
795*4882a593Smuzhiyun ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
796*4882a593Smuzhiyun if (ret) {
797*4882a593Smuzhiyun dev_err(nt->dev, "failed to enter sleep mode (%d)\n", ret);
798*4882a593Smuzhiyun return ret;
799*4882a593Smuzhiyun }
800*4882a593Smuzhiyun
801*4882a593Smuzhiyun /* Wait 4 frames, how much is that 5ms in the vendor driver */
802*4882a593Smuzhiyun usleep_range(5000, 10000);
803*4882a593Smuzhiyun
804*4882a593Smuzhiyun ret = nt35510_power_off(nt);
805*4882a593Smuzhiyun if (ret)
806*4882a593Smuzhiyun return ret;
807*4882a593Smuzhiyun
808*4882a593Smuzhiyun return 0;
809*4882a593Smuzhiyun }
810*4882a593Smuzhiyun
nt35510_prepare(struct drm_panel * panel)811*4882a593Smuzhiyun static int nt35510_prepare(struct drm_panel *panel)
812*4882a593Smuzhiyun {
813*4882a593Smuzhiyun struct nt35510 *nt = panel_to_nt35510(panel);
814*4882a593Smuzhiyun struct mipi_dsi_device *dsi = to_mipi_dsi_device(nt->dev);
815*4882a593Smuzhiyun int ret;
816*4882a593Smuzhiyun
817*4882a593Smuzhiyun ret = nt35510_power_on(nt);
818*4882a593Smuzhiyun if (ret)
819*4882a593Smuzhiyun return ret;
820*4882a593Smuzhiyun
821*4882a593Smuzhiyun /* Exit sleep mode */
822*4882a593Smuzhiyun ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
823*4882a593Smuzhiyun if (ret) {
824*4882a593Smuzhiyun dev_err(nt->dev, "failed to exit sleep mode (%d)\n", ret);
825*4882a593Smuzhiyun return ret;
826*4882a593Smuzhiyun }
827*4882a593Smuzhiyun /* Up to 120 ms */
828*4882a593Smuzhiyun usleep_range(120000, 150000);
829*4882a593Smuzhiyun
830*4882a593Smuzhiyun ret = mipi_dsi_dcs_set_display_on(dsi);
831*4882a593Smuzhiyun if (ret) {
832*4882a593Smuzhiyun dev_err(nt->dev, "failed to turn display on (%d)\n", ret);
833*4882a593Smuzhiyun return ret;
834*4882a593Smuzhiyun }
835*4882a593Smuzhiyun /* Some 10 ms */
836*4882a593Smuzhiyun usleep_range(10000, 20000);
837*4882a593Smuzhiyun
838*4882a593Smuzhiyun return 0;
839*4882a593Smuzhiyun }
840*4882a593Smuzhiyun
nt35510_get_modes(struct drm_panel * panel,struct drm_connector * connector)841*4882a593Smuzhiyun static int nt35510_get_modes(struct drm_panel *panel,
842*4882a593Smuzhiyun struct drm_connector *connector)
843*4882a593Smuzhiyun {
844*4882a593Smuzhiyun struct nt35510 *nt = panel_to_nt35510(panel);
845*4882a593Smuzhiyun struct drm_display_mode *mode;
846*4882a593Smuzhiyun struct drm_display_info *info;
847*4882a593Smuzhiyun
848*4882a593Smuzhiyun info = &connector->display_info;
849*4882a593Smuzhiyun info->width_mm = nt->conf->width_mm;
850*4882a593Smuzhiyun info->height_mm = nt->conf->height_mm;
851*4882a593Smuzhiyun mode = drm_mode_duplicate(connector->dev, &nt->conf->mode);
852*4882a593Smuzhiyun if (!mode) {
853*4882a593Smuzhiyun dev_err(panel->dev, "bad mode or failed to add mode\n");
854*4882a593Smuzhiyun return -EINVAL;
855*4882a593Smuzhiyun }
856*4882a593Smuzhiyun drm_mode_set_name(mode);
857*4882a593Smuzhiyun mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
858*4882a593Smuzhiyun
859*4882a593Smuzhiyun mode->width_mm = nt->conf->width_mm;
860*4882a593Smuzhiyun mode->height_mm = nt->conf->height_mm;
861*4882a593Smuzhiyun drm_mode_probed_add(connector, mode);
862*4882a593Smuzhiyun
863*4882a593Smuzhiyun return 1; /* Number of modes */
864*4882a593Smuzhiyun }
865*4882a593Smuzhiyun
866*4882a593Smuzhiyun static const struct drm_panel_funcs nt35510_drm_funcs = {
867*4882a593Smuzhiyun .unprepare = nt35510_unprepare,
868*4882a593Smuzhiyun .prepare = nt35510_prepare,
869*4882a593Smuzhiyun .get_modes = nt35510_get_modes,
870*4882a593Smuzhiyun };
871*4882a593Smuzhiyun
nt35510_probe(struct mipi_dsi_device * dsi)872*4882a593Smuzhiyun static int nt35510_probe(struct mipi_dsi_device *dsi)
873*4882a593Smuzhiyun {
874*4882a593Smuzhiyun struct device *dev = &dsi->dev;
875*4882a593Smuzhiyun struct nt35510 *nt;
876*4882a593Smuzhiyun int ret;
877*4882a593Smuzhiyun
878*4882a593Smuzhiyun nt = devm_kzalloc(dev, sizeof(struct nt35510), GFP_KERNEL);
879*4882a593Smuzhiyun if (!nt)
880*4882a593Smuzhiyun return -ENOMEM;
881*4882a593Smuzhiyun mipi_dsi_set_drvdata(dsi, nt);
882*4882a593Smuzhiyun nt->dev = dev;
883*4882a593Smuzhiyun
884*4882a593Smuzhiyun dsi->lanes = 2;
885*4882a593Smuzhiyun dsi->format = MIPI_DSI_FMT_RGB888;
886*4882a593Smuzhiyun /*
887*4882a593Smuzhiyun * Datasheet suggests max HS rate for NT35510 is 250 MHz
888*4882a593Smuzhiyun * (period time 4ns, see figure 7.6.4 page 365) and max LP rate is
889*4882a593Smuzhiyun * 20 MHz (period time 50ns, see figure 7.6.6. page 366).
890*4882a593Smuzhiyun * However these frequencies appear in source code for the Hydis
891*4882a593Smuzhiyun * HVA40WV1 panel and setting up the LP frequency makes the panel
892*4882a593Smuzhiyun * not work.
893*4882a593Smuzhiyun *
894*4882a593Smuzhiyun * TODO: if other panels prove to be closer to the datasheet,
895*4882a593Smuzhiyun * maybe make this a per-panel config in struct nt35510_config?
896*4882a593Smuzhiyun */
897*4882a593Smuzhiyun dsi->hs_rate = 349440000;
898*4882a593Smuzhiyun dsi->lp_rate = 9600000;
899*4882a593Smuzhiyun dsi->mode_flags = MIPI_DSI_CLOCK_NON_CONTINUOUS;
900*4882a593Smuzhiyun
901*4882a593Smuzhiyun /*
902*4882a593Smuzhiyun * Every new incarnation of this display must have a unique
903*4882a593Smuzhiyun * data entry for the system in this driver.
904*4882a593Smuzhiyun */
905*4882a593Smuzhiyun nt->conf = of_device_get_match_data(dev);
906*4882a593Smuzhiyun if (!nt->conf) {
907*4882a593Smuzhiyun dev_err(dev, "missing device configuration\n");
908*4882a593Smuzhiyun return -ENODEV;
909*4882a593Smuzhiyun }
910*4882a593Smuzhiyun
911*4882a593Smuzhiyun nt->supplies[0].supply = "vdd"; /* 2.3-4.8 V */
912*4882a593Smuzhiyun nt->supplies[1].supply = "vddi"; /* 1.65-3.3V */
913*4882a593Smuzhiyun ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(nt->supplies),
914*4882a593Smuzhiyun nt->supplies);
915*4882a593Smuzhiyun if (ret < 0)
916*4882a593Smuzhiyun return ret;
917*4882a593Smuzhiyun ret = regulator_set_voltage(nt->supplies[0].consumer,
918*4882a593Smuzhiyun 2300000, 4800000);
919*4882a593Smuzhiyun if (ret)
920*4882a593Smuzhiyun return ret;
921*4882a593Smuzhiyun ret = regulator_set_voltage(nt->supplies[1].consumer,
922*4882a593Smuzhiyun 1650000, 3300000);
923*4882a593Smuzhiyun if (ret)
924*4882a593Smuzhiyun return ret;
925*4882a593Smuzhiyun
926*4882a593Smuzhiyun nt->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS);
927*4882a593Smuzhiyun if (IS_ERR(nt->reset_gpio)) {
928*4882a593Smuzhiyun dev_err(dev, "error getting RESET GPIO\n");
929*4882a593Smuzhiyun return PTR_ERR(nt->reset_gpio);
930*4882a593Smuzhiyun }
931*4882a593Smuzhiyun
932*4882a593Smuzhiyun drm_panel_init(&nt->panel, dev, &nt35510_drm_funcs,
933*4882a593Smuzhiyun DRM_MODE_CONNECTOR_DSI);
934*4882a593Smuzhiyun
935*4882a593Smuzhiyun /*
936*4882a593Smuzhiyun * First, try to locate an external backlight (such as on GPIO)
937*4882a593Smuzhiyun * if this fails, assume we will want to use the internal backlight
938*4882a593Smuzhiyun * control.
939*4882a593Smuzhiyun */
940*4882a593Smuzhiyun ret = drm_panel_of_backlight(&nt->panel);
941*4882a593Smuzhiyun if (ret) {
942*4882a593Smuzhiyun dev_err(dev, "error getting external backlight %d\n", ret);
943*4882a593Smuzhiyun return ret;
944*4882a593Smuzhiyun }
945*4882a593Smuzhiyun if (!nt->panel.backlight) {
946*4882a593Smuzhiyun struct backlight_device *bl;
947*4882a593Smuzhiyun
948*4882a593Smuzhiyun bl = devm_backlight_device_register(dev, "nt35510", dev, nt,
949*4882a593Smuzhiyun &nt35510_bl_ops, NULL);
950*4882a593Smuzhiyun if (IS_ERR(bl)) {
951*4882a593Smuzhiyun dev_err(dev, "failed to register backlight device\n");
952*4882a593Smuzhiyun return PTR_ERR(bl);
953*4882a593Smuzhiyun }
954*4882a593Smuzhiyun bl->props.max_brightness = 255;
955*4882a593Smuzhiyun bl->props.brightness = 255;
956*4882a593Smuzhiyun bl->props.power = FB_BLANK_POWERDOWN;
957*4882a593Smuzhiyun nt->panel.backlight = bl;
958*4882a593Smuzhiyun }
959*4882a593Smuzhiyun
960*4882a593Smuzhiyun drm_panel_add(&nt->panel);
961*4882a593Smuzhiyun
962*4882a593Smuzhiyun ret = mipi_dsi_attach(dsi);
963*4882a593Smuzhiyun if (ret < 0)
964*4882a593Smuzhiyun drm_panel_remove(&nt->panel);
965*4882a593Smuzhiyun
966*4882a593Smuzhiyun return 0;
967*4882a593Smuzhiyun }
968*4882a593Smuzhiyun
nt35510_remove(struct mipi_dsi_device * dsi)969*4882a593Smuzhiyun static int nt35510_remove(struct mipi_dsi_device *dsi)
970*4882a593Smuzhiyun {
971*4882a593Smuzhiyun struct nt35510 *nt = mipi_dsi_get_drvdata(dsi);
972*4882a593Smuzhiyun int ret;
973*4882a593Smuzhiyun
974*4882a593Smuzhiyun mipi_dsi_detach(dsi);
975*4882a593Smuzhiyun /* Power off */
976*4882a593Smuzhiyun ret = nt35510_power_off(nt);
977*4882a593Smuzhiyun drm_panel_remove(&nt->panel);
978*4882a593Smuzhiyun
979*4882a593Smuzhiyun return ret;
980*4882a593Smuzhiyun }
981*4882a593Smuzhiyun
982*4882a593Smuzhiyun /*
983*4882a593Smuzhiyun * These gamma correction values are 10bit tuples, so only bits 0 and 1 is
984*4882a593Smuzhiyun * ever used in the first byte. They form a positive and negative gamma
985*4882a593Smuzhiyun * correction curve for each color, values must be strictly higher for each
986*4882a593Smuzhiyun * step on the curve. As can be seen these default curves goes from 0x0001
987*4882a593Smuzhiyun * to 0x03FE.
988*4882a593Smuzhiyun */
989*4882a593Smuzhiyun #define NT35510_GAMMA_POS_DEFAULT 0x00, 0x01, 0x00, 0x43, 0x00, \
990*4882a593Smuzhiyun 0x6B, 0x00, 0x87, 0x00, 0xA3, 0x00, 0xCE, 0x00, 0xF1, 0x01, \
991*4882a593Smuzhiyun 0x27, 0x01, 0x53, 0x01, 0x98, 0x01, 0xCE, 0x02, 0x22, 0x02, \
992*4882a593Smuzhiyun 0x83, 0x02, 0x78, 0x02, 0x9E, 0x02, 0xDD, 0x03, 0x00, 0x03, \
993*4882a593Smuzhiyun 0x2E, 0x03, 0x54, 0x03, 0x7F, 0x03, 0x95, 0x03, 0xB3, 0x03, \
994*4882a593Smuzhiyun 0xC2, 0x03, 0xE1, 0x03, 0xF1, 0x03, 0xFE
995*4882a593Smuzhiyun
996*4882a593Smuzhiyun #define NT35510_GAMMA_NEG_DEFAULT 0x00, 0x01, 0x00, 0x43, 0x00, \
997*4882a593Smuzhiyun 0x6B, 0x00, 0x87, 0x00, 0xA3, 0x00, 0xCE, 0x00, 0xF1, 0x01, \
998*4882a593Smuzhiyun 0x27, 0x01, 0x53, 0x01, 0x98, 0x01, 0xCE, 0x02, 0x22, 0x02, \
999*4882a593Smuzhiyun 0x43, 0x02, 0x50, 0x02, 0x9E, 0x02, 0xDD, 0x03, 0x00, 0x03, \
1000*4882a593Smuzhiyun 0x2E, 0x03, 0x54, 0x03, 0x7F, 0x03, 0x95, 0x03, 0xB3, 0x03, \
1001*4882a593Smuzhiyun 0xC2, 0x03, 0xE1, 0x03, 0xF1, 0x03, 0xFE
1002*4882a593Smuzhiyun
1003*4882a593Smuzhiyun /*
1004*4882a593Smuzhiyun * The Hydis HVA40WV1 panel
1005*4882a593Smuzhiyun */
1006*4882a593Smuzhiyun static const struct nt35510_config nt35510_hydis_hva40wv1 = {
1007*4882a593Smuzhiyun .width_mm = 52,
1008*4882a593Smuzhiyun .height_mm = 86,
1009*4882a593Smuzhiyun /**
1010*4882a593Smuzhiyun * As the Hydis panel is used in command mode, the porches etc
1011*4882a593Smuzhiyun * are settings programmed internally into the NT35510 controller
1012*4882a593Smuzhiyun * and generated toward the physical display. As the panel is not
1013*4882a593Smuzhiyun * used in video mode, these are not really exposed to the DSI
1014*4882a593Smuzhiyun * host.
1015*4882a593Smuzhiyun *
1016*4882a593Smuzhiyun * Display frame rate control:
1017*4882a593Smuzhiyun * Frame rate = (20 MHz / 1) / (389 * (7 + 50 + 800)) ~= 60 Hz
1018*4882a593Smuzhiyun */
1019*4882a593Smuzhiyun .mode = {
1020*4882a593Smuzhiyun /* The internal pixel clock of the NT35510 is 20 MHz */
1021*4882a593Smuzhiyun .clock = 20000,
1022*4882a593Smuzhiyun .hdisplay = 480,
1023*4882a593Smuzhiyun .hsync_start = 480 + 2, /* HFP = 2 */
1024*4882a593Smuzhiyun .hsync_end = 480 + 2 + 0, /* HSync = 0 */
1025*4882a593Smuzhiyun .htotal = 480 + 2 + 0 + 5, /* HFP = 5 */
1026*4882a593Smuzhiyun .vdisplay = 800,
1027*4882a593Smuzhiyun .vsync_start = 800 + 2, /* VFP = 2 */
1028*4882a593Smuzhiyun .vsync_end = 800 + 2 + 0, /* VSync = 0 */
1029*4882a593Smuzhiyun .vtotal = 800 + 2 + 0 + 5, /* VBP = 5 */
1030*4882a593Smuzhiyun .flags = 0,
1031*4882a593Smuzhiyun },
1032*4882a593Smuzhiyun /* 0x09: AVDD = 5.6V */
1033*4882a593Smuzhiyun .avdd = { 0x09, 0x09, 0x09 },
1034*4882a593Smuzhiyun /* 0x34: PCK = Hsync/2, BTP = 2 x VDDB */
1035*4882a593Smuzhiyun .bt1ctr = { 0x34, 0x34, 0x34 },
1036*4882a593Smuzhiyun /* 0x09: AVEE = -5.6V */
1037*4882a593Smuzhiyun .avee = { 0x09, 0x09, 0x09 },
1038*4882a593Smuzhiyun /* 0x24: NCK = Hsync/2, BTN = -2 x VDDB */
1039*4882a593Smuzhiyun .bt2ctr = { 0x24, 0x24, 0x24 },
1040*4882a593Smuzhiyun /* 0x05 = 12V */
1041*4882a593Smuzhiyun .vgh = { 0x05, 0x05, 0x05 },
1042*4882a593Smuzhiyun /* 0x24: NCKA = Hsync/2, VGH = 2 x AVDD - AVEE */
1043*4882a593Smuzhiyun .bt4ctr = { 0x24, 0x24, 0x24 },
1044*4882a593Smuzhiyun /* 0x0B = -13V */
1045*4882a593Smuzhiyun .vgl = { 0x0B, 0x0B, 0x0B },
1046*4882a593Smuzhiyun /* 0x24: LCKA = Hsync, VGL = AVDD + VCL - AVDD */
1047*4882a593Smuzhiyun .bt5ctr = { 0x24, 0x24, 0x24 },
1048*4882a593Smuzhiyun /* VGMP: 0x0A3 = 5.0375V, VGSP = 0V */
1049*4882a593Smuzhiyun .vgp = { 0x00, 0xA3, 0x00 },
1050*4882a593Smuzhiyun /* VGMP: 0x0A3 = 5.0375V, VGSP = 0V */
1051*4882a593Smuzhiyun .vgn = { 0x00, 0xA3, 0x00 },
1052*4882a593Smuzhiyun /* SDEQCTR: source driver EQ mode 2, 2.5 us rise time on each step */
1053*4882a593Smuzhiyun .sdeqctr = { 0x01, 0x05, 0x05, 0x05 },
1054*4882a593Smuzhiyun /* SDVPCTR: Normal operation off color during v porch */
1055*4882a593Smuzhiyun .sdvpctr = 0x01,
1056*4882a593Smuzhiyun /* T1: number of pixel clocks on one scanline: 0x184 = 389 clocks */
1057*4882a593Smuzhiyun .t1 = 0x0184,
1058*4882a593Smuzhiyun /* VBP: vertical back porch toward the panel */
1059*4882a593Smuzhiyun .vbp = 7,
1060*4882a593Smuzhiyun /* VFP: vertical front porch toward the panel */
1061*4882a593Smuzhiyun .vfp = 50,
1062*4882a593Smuzhiyun /* PSEL: divide pixel clock 20MHz with 1 (no clock downscaling) */
1063*4882a593Smuzhiyun .psel = 0,
1064*4882a593Smuzhiyun /* DPTMCTR12: 0x03: LVGL = VGLX, overlap mode, swap R->L O->E */
1065*4882a593Smuzhiyun .dpmctr12 = { 0x03, 0x00, 0x00, },
1066*4882a593Smuzhiyun /* Default gamma correction values */
1067*4882a593Smuzhiyun .gamma_corr_pos_r = { NT35510_GAMMA_POS_DEFAULT },
1068*4882a593Smuzhiyun .gamma_corr_pos_g = { NT35510_GAMMA_POS_DEFAULT },
1069*4882a593Smuzhiyun .gamma_corr_pos_b = { NT35510_GAMMA_POS_DEFAULT },
1070*4882a593Smuzhiyun .gamma_corr_neg_r = { NT35510_GAMMA_NEG_DEFAULT },
1071*4882a593Smuzhiyun .gamma_corr_neg_g = { NT35510_GAMMA_NEG_DEFAULT },
1072*4882a593Smuzhiyun .gamma_corr_neg_b = { NT35510_GAMMA_NEG_DEFAULT },
1073*4882a593Smuzhiyun };
1074*4882a593Smuzhiyun
1075*4882a593Smuzhiyun static const struct of_device_id nt35510_of_match[] = {
1076*4882a593Smuzhiyun {
1077*4882a593Smuzhiyun .compatible = "hydis,hva40wv1",
1078*4882a593Smuzhiyun .data = &nt35510_hydis_hva40wv1,
1079*4882a593Smuzhiyun },
1080*4882a593Smuzhiyun { }
1081*4882a593Smuzhiyun };
1082*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, nt35510_of_match);
1083*4882a593Smuzhiyun
1084*4882a593Smuzhiyun static struct mipi_dsi_driver nt35510_driver = {
1085*4882a593Smuzhiyun .probe = nt35510_probe,
1086*4882a593Smuzhiyun .remove = nt35510_remove,
1087*4882a593Smuzhiyun .driver = {
1088*4882a593Smuzhiyun .name = "panel-novatek-nt35510",
1089*4882a593Smuzhiyun .of_match_table = nt35510_of_match,
1090*4882a593Smuzhiyun },
1091*4882a593Smuzhiyun };
1092*4882a593Smuzhiyun module_mipi_dsi_driver(nt35510_driver);
1093*4882a593Smuzhiyun
1094*4882a593Smuzhiyun MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
1095*4882a593Smuzhiyun MODULE_DESCRIPTION("NT35510-based panel driver");
1096*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
1097