1 // SPDX-License-Identifier: GPL-2.0-only
2 /* drivers/video/backlight/vgg2432a4.c
4 * VGG2432A4 (ILI9320) LCD controller driver.
6 * Copyright 2007 Simtec Electronics
7 * http://armlinux.simtec.co.uk/
8 * Ben Dooks <ben@simtec.co.uk>
11 #include <linux/delay.h>
12 #include <linux/err.h>
14 #include <linux/init.h>
15 #include <linux/lcd.h>
16 #include <linux/module.h>
18 #include <linux/spi/spi.h>
20 #include <video/ili9320.h>
24 /* Device initialisation sequences */
26 static const struct ili9320_reg vgg_init1
[] = {
28 .address
= ILI9320_POWER1
,
29 .value
= ILI9320_POWER1_AP(0) | ILI9320_POWER1_BT(0),
31 .address
= ILI9320_POWER2
,
32 .value
= (ILI9320_POWER2_VC(7) |
33 ILI9320_POWER2_DC0(0) | ILI9320_POWER2_DC1(0)),
35 .address
= ILI9320_POWER3
,
36 .value
= ILI9320_POWER3_VRH(0),
38 .address
= ILI9320_POWER4
,
39 .value
= ILI9320_POWER4_VREOUT(0),
43 static const struct ili9320_reg vgg_init2
[] = {
45 .address
= ILI9320_POWER1
,
46 .value
= (ILI9320_POWER1_AP(3) | ILI9320_POWER1_APE
|
47 ILI9320_POWER1_BT(7) | ILI9320_POWER1_SAP
),
49 .address
= ILI9320_POWER2
,
50 .value
= ILI9320_POWER2_VC(7) | ILI9320_POWER2_DC0(3),
54 static const struct ili9320_reg vgg_gamma
[] = {
56 .address
= ILI9320_GAMMA1
,
59 .address
= ILI9320_GAMMA2
,
62 .address
= ILI9320_GAMMA3
,
65 .address
= ILI9320_GAMMA4
,
68 .address
= ILI9320_GAMMA5
,
71 .address
= ILI9320_GAMMA6
,
74 .address
= ILI9320_GAMMA7
,
77 .address
= ILI9320_GAMMA8
,
80 .address
= ILI9320_GAMMA9
,
83 .address
= ILI9320_GAMMA10
,
89 static const struct ili9320_reg vgg_init0
[] = {
91 /* set direction and scan mode gate */
92 .address
= ILI9320_DRIVER
,
93 .value
= ILI9320_DRIVER_SS
,
95 .address
= ILI9320_DRIVEWAVE
,
96 .value
= (ILI9320_DRIVEWAVE_MUSTSET
|
97 ILI9320_DRIVEWAVE_EOR
| ILI9320_DRIVEWAVE_BC
),
99 .address
= ILI9320_ENTRYMODE
,
100 .value
= ILI9320_ENTRYMODE_ID(3) | ILI9320_ENTRYMODE_BGR
,
102 .address
= ILI9320_RESIZING
,
108 static int vgg2432a4_lcd_init(struct ili9320
*lcd
,
109 struct ili9320_platdata
*cfg
)
114 /* Set VCore before anything else (VGG243237-6UFLWA) */
115 ret
= ili9320_write(lcd
, 0x00e5, 0x8000);
119 /* Start the oscillator up before we can do anything else. */
120 ret
= ili9320_write(lcd
, ILI9320_OSCILATION
, ILI9320_OSCILATION_OSC
);
124 /* must wait at-lesat 10ms after starting */
127 ret
= ili9320_write_regs(lcd
, vgg_init0
, ARRAY_SIZE(vgg_init0
));
131 ili9320_write(lcd
, ILI9320_DISPLAY2
, cfg
->display2
);
132 ili9320_write(lcd
, ILI9320_DISPLAY3
, cfg
->display3
);
133 ili9320_write(lcd
, ILI9320_DISPLAY4
, cfg
->display4
);
135 ili9320_write(lcd
, ILI9320_RGB_IF1
, cfg
->rgb_if1
);
136 ili9320_write(lcd
, ILI9320_FRAMEMAKER
, 0x0);
137 ili9320_write(lcd
, ILI9320_RGB_IF2
, cfg
->rgb_if2
);
139 ret
= ili9320_write_regs(lcd
, vgg_init1
, ARRAY_SIZE(vgg_init1
));
145 ret
= ili9320_write_regs(lcd
, vgg_init2
, ARRAY_SIZE(vgg_init2
));
151 ili9320_write(lcd
, ILI9320_POWER3
, 0x13c);
155 ili9320_write(lcd
, ILI9320_POWER4
, 0x1c00);
156 ili9320_write(lcd
, ILI9320_POWER7
, 0x000e);
160 ili9320_write(lcd
, ILI9320_GRAM_HORIZ_ADDR
, 0x00);
161 ili9320_write(lcd
, ILI9320_GRAM_VERT_ADD
, 0x00);
163 ret
= ili9320_write_regs(lcd
, vgg_gamma
, ARRAY_SIZE(vgg_gamma
));
167 ili9320_write(lcd
, ILI9320_HORIZ_START
, 0x0);
168 ili9320_write(lcd
, ILI9320_HORIZ_END
, cfg
->hsize
- 1);
169 ili9320_write(lcd
, ILI9320_VERT_START
, 0x0);
170 ili9320_write(lcd
, ILI9320_VERT_END
, cfg
->vsize
- 1);
172 ili9320_write(lcd
, ILI9320_DRIVER2
,
173 ILI9320_DRIVER2_NL(((cfg
->vsize
- 240) / 8) + 0x1D));
175 ili9320_write(lcd
, ILI9320_BASE_IMAGE
, 0x1);
176 ili9320_write(lcd
, ILI9320_VERT_SCROLL
, 0x00);
178 for (addr
= ILI9320_PARTIAL1_POSITION
; addr
<= ILI9320_PARTIAL2_END
;
180 ili9320_write(lcd
, addr
, 0x0);
183 ili9320_write(lcd
, ILI9320_INTERFACE1
, 0x10);
184 ili9320_write(lcd
, ILI9320_INTERFACE2
, cfg
->interface2
);
185 ili9320_write(lcd
, ILI9320_INTERFACE3
, cfg
->interface3
);
186 ili9320_write(lcd
, ILI9320_INTERFACE4
, cfg
->interface4
);
187 ili9320_write(lcd
, ILI9320_INTERFACE5
, cfg
->interface5
);
188 ili9320_write(lcd
, ILI9320_INTERFACE6
, cfg
->interface6
);
190 lcd
->display1
= (ILI9320_DISPLAY1_D(3) | ILI9320_DISPLAY1_DTE
|
191 ILI9320_DISPLAY1_GON
| ILI9320_DISPLAY1_BASEE
|
194 ili9320_write(lcd
, ILI9320_DISPLAY1
, lcd
->display1
);
205 #ifdef CONFIG_PM_SLEEP
206 static int vgg2432a4_suspend(struct device
*dev
)
208 return ili9320_suspend(dev_get_drvdata(dev
));
210 static int vgg2432a4_resume(struct device
*dev
)
212 return ili9320_resume(dev_get_drvdata(dev
));
216 static struct ili9320_client vgg2432a4_client
= {
218 .init
= vgg2432a4_lcd_init
,
223 static int vgg2432a4_probe(struct spi_device
*spi
)
227 ret
= ili9320_probe_spi(spi
, &vgg2432a4_client
);
229 dev_err(&spi
->dev
, "failed to initialise ili9320\n");
236 static int vgg2432a4_remove(struct spi_device
*spi
)
238 return ili9320_remove(spi_get_drvdata(spi
));
241 static void vgg2432a4_shutdown(struct spi_device
*spi
)
243 ili9320_shutdown(spi_get_drvdata(spi
));
246 static SIMPLE_DEV_PM_OPS(vgg2432a4_pm_ops
, vgg2432a4_suspend
, vgg2432a4_resume
);
248 static struct spi_driver vgg2432a4_driver
= {
251 .pm
= &vgg2432a4_pm_ops
,
253 .probe
= vgg2432a4_probe
,
254 .remove
= vgg2432a4_remove
,
255 .shutdown
= vgg2432a4_shutdown
,
258 module_spi_driver(vgg2432a4_driver
);
260 MODULE_AUTHOR("Ben Dooks <ben-linux@fluff.org>");
261 MODULE_DESCRIPTION("VGG2432A4 LCD Driver");
262 MODULE_LICENSE("GPL v2");
263 MODULE_ALIAS("spi:VGG2432A4");