treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / video / backlight / vgg2432a4.c
blob9bf277ca4ae94f114cbd4bc8ef04e106965f0aaa
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>
9 */
11 #include <linux/delay.h>
12 #include <linux/err.h>
13 #include <linux/fb.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>
22 #include "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),
30 }, {
31 .address = ILI9320_POWER2,
32 .value = (ILI9320_POWER2_VC(7) |
33 ILI9320_POWER2_DC0(0) | ILI9320_POWER2_DC1(0)),
34 }, {
35 .address = ILI9320_POWER3,
36 .value = ILI9320_POWER3_VRH(0),
37 }, {
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),
48 }, {
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,
57 .value = 0x0000,
58 }, {
59 .address = ILI9320_GAMMA2,
60 .value = 0x0505,
61 }, {
62 .address = ILI9320_GAMMA3,
63 .value = 0x0004,
64 }, {
65 .address = ILI9320_GAMMA4,
66 .value = 0x0006,
67 }, {
68 .address = ILI9320_GAMMA5,
69 .value = 0x0707,
70 }, {
71 .address = ILI9320_GAMMA6,
72 .value = 0x0105,
73 }, {
74 .address = ILI9320_GAMMA7,
75 .value = 0x0002,
76 }, {
77 .address = ILI9320_GAMMA8,
78 .value = 0x0707,
79 }, {
80 .address = ILI9320_GAMMA9,
81 .value = 0x0704,
82 }, {
83 .address = ILI9320_GAMMA10,
84 .value = 0x807,
89 static const struct ili9320_reg vgg_init0[] = {
90 [0] = {
91 /* set direction and scan mode gate */
92 .address = ILI9320_DRIVER,
93 .value = ILI9320_DRIVER_SS,
94 }, {
95 .address = ILI9320_DRIVEWAVE,
96 .value = (ILI9320_DRIVEWAVE_MUSTSET |
97 ILI9320_DRIVEWAVE_EOR | ILI9320_DRIVEWAVE_BC),
98 }, {
99 .address = ILI9320_ENTRYMODE,
100 .value = ILI9320_ENTRYMODE_ID(3) | ILI9320_ENTRYMODE_BGR,
101 }, {
102 .address = ILI9320_RESIZING,
103 .value = 0x0,
108 static int vgg2432a4_lcd_init(struct ili9320 *lcd,
109 struct ili9320_platdata *cfg)
111 unsigned int addr;
112 int ret;
114 /* Set VCore before anything else (VGG243237-6UFLWA) */
115 ret = ili9320_write(lcd, 0x00e5, 0x8000);
116 if (ret)
117 goto err_initial;
119 /* Start the oscillator up before we can do anything else. */
120 ret = ili9320_write(lcd, ILI9320_OSCILATION, ILI9320_OSCILATION_OSC);
121 if (ret)
122 goto err_initial;
124 /* must wait at-lesat 10ms after starting */
125 mdelay(15);
127 ret = ili9320_write_regs(lcd, vgg_init0, ARRAY_SIZE(vgg_init0));
128 if (ret != 0)
129 goto err_initial;
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));
140 if (ret != 0)
141 goto err_vgg;
143 mdelay(300);
145 ret = ili9320_write_regs(lcd, vgg_init2, ARRAY_SIZE(vgg_init2));
146 if (ret != 0)
147 goto err_vgg2;
149 mdelay(100);
151 ili9320_write(lcd, ILI9320_POWER3, 0x13c);
153 mdelay(100);
155 ili9320_write(lcd, ILI9320_POWER4, 0x1c00);
156 ili9320_write(lcd, ILI9320_POWER7, 0x000e);
158 mdelay(100);
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));
164 if (ret != 0)
165 goto err_vgg3;
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;
179 addr++) {
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 |
192 0x40);
194 ili9320_write(lcd, ILI9320_DISPLAY1, lcd->display1);
196 return 0;
198 err_vgg3:
199 err_vgg2:
200 err_vgg:
201 err_initial:
202 return ret;
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));
214 #endif
216 static struct ili9320_client vgg2432a4_client = {
217 .name = "VGG2432A4",
218 .init = vgg2432a4_lcd_init,
221 /* Device probe */
223 static int vgg2432a4_probe(struct spi_device *spi)
225 int ret;
227 ret = ili9320_probe_spi(spi, &vgg2432a4_client);
228 if (ret != 0) {
229 dev_err(&spi->dev, "failed to initialise ili9320\n");
230 return ret;
233 return 0;
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 = {
249 .driver = {
250 .name = "VGG2432A4",
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");