]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/gpu/drm/omapdrm/displays/panel-nec-nl8048hl11.c
video: omapfb2: Make standard and custom panel drivers mutually exclusive
[linux.git] / drivers / gpu / drm / omapdrm / displays / panel-nec-nl8048hl11.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * NEC NL8048HL11 Panel driver
4  *
5  * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
6  * Author: Erik Gilling <konkers@android.com>
7  * Converted to new DSS device model: Tomi Valkeinen <tomi.valkeinen@ti.com>
8  */
9
10 #include <linux/delay.h>
11 #include <linux/gpio/consumer.h>
12 #include <linux/module.h>
13 #include <linux/spi/spi.h>
14
15 #include "../dss/omapdss.h"
16
17 struct panel_drv_data {
18         struct omap_dss_device  dssdev;
19
20         struct videomode vm;
21
22         struct gpio_desc *res_gpio;
23
24         struct spi_device *spi;
25 };
26
27 #define LCD_XRES                800
28 #define LCD_YRES                480
29 /*
30  * NEC PIX Clock Ratings
31  * MIN:21.8MHz TYP:23.8MHz MAX:25.7MHz
32  */
33 #define LCD_PIXEL_CLOCK         23800000
34
35 static const struct {
36         unsigned char addr;
37         unsigned char dat;
38 } nec_8048_init_seq[] = {
39         { 3, 0x01 }, { 0, 0x00 }, { 1, 0x01 }, { 4, 0x00 }, { 5, 0x14 },
40         { 6, 0x24 }, { 16, 0xD7 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x55 },
41         { 20, 0x01 }, { 21, 0x70 }, { 22, 0x1E }, { 23, 0x25 }, { 24, 0x25 },
42         { 25, 0x02 }, { 26, 0x02 }, { 27, 0xA0 }, { 32, 0x2F }, { 33, 0x0F },
43         { 34, 0x0F }, { 35, 0x0F }, { 36, 0x0F }, { 37, 0x0F }, { 38, 0x0F },
44         { 39, 0x00 }, { 40, 0x02 }, { 41, 0x02 }, { 42, 0x02 }, { 43, 0x0F },
45         { 44, 0x0F }, { 45, 0x0F }, { 46, 0x0F }, { 47, 0x0F }, { 48, 0x0F },
46         { 49, 0x0F }, { 50, 0x00 }, { 51, 0x02 }, { 52, 0x02 }, { 53, 0x02 },
47         { 80, 0x0C }, { 83, 0x42 }, { 84, 0x42 }, { 85, 0x41 }, { 86, 0x14 },
48         { 89, 0x88 }, { 90, 0x01 }, { 91, 0x00 }, { 92, 0x02 }, { 93, 0x0C },
49         { 94, 0x1C }, { 95, 0x27 }, { 98, 0x49 }, { 99, 0x27 }, { 102, 0x76 },
50         { 103, 0x27 }, { 112, 0x01 }, { 113, 0x0E }, { 114, 0x02 },
51         { 115, 0x0C }, { 118, 0x0C }, { 121, 0x30 }, { 130, 0x00 },
52         { 131, 0x00 }, { 132, 0xFC }, { 134, 0x00 }, { 136, 0x00 },
53         { 138, 0x00 }, { 139, 0x00 }, { 140, 0x00 }, { 141, 0xFC },
54         { 143, 0x00 }, { 145, 0x00 }, { 147, 0x00 }, { 148, 0x00 },
55         { 149, 0x00 }, { 150, 0xFC }, { 152, 0x00 }, { 154, 0x00 },
56         { 156, 0x00 }, { 157, 0x00 }, { 2, 0x00 },
57 };
58
59 static const struct videomode nec_8048_panel_vm = {
60         .hactive        = LCD_XRES,
61         .vactive        = LCD_YRES,
62         .pixelclock     = LCD_PIXEL_CLOCK,
63         .hfront_porch   = 6,
64         .hsync_len      = 1,
65         .hback_porch    = 4,
66         .vfront_porch   = 3,
67         .vsync_len      = 1,
68         .vback_porch    = 4,
69
70         .flags          = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW,
71 };
72
73 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
74
75 static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
76                         unsigned char reg_data)
77 {
78         int ret = 0;
79         unsigned int cmd = 0, data = 0;
80
81         cmd = 0x0000 | reg_addr; /* register address write */
82         data = 0x0100 | reg_data; /* register data write */
83         data = (cmd << 16) | data;
84
85         ret = spi_write(spi, (unsigned char *)&data, 4);
86         if (ret)
87                 pr_err("error in spi_write %x\n", data);
88
89         return ret;
90 }
91
92 static int init_nec_8048_wvga_lcd(struct spi_device *spi)
93 {
94         unsigned int i;
95         /* Initialization Sequence */
96         /* nec_8048_spi_send(spi, REG, VAL) */
97         for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
98                 nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
99                                 nec_8048_init_seq[i].dat);
100         udelay(20);
101         nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
102                                 nec_8048_init_seq[i].dat);
103         return 0;
104 }
105
106 static int nec_8048_connect(struct omap_dss_device *src,
107                             struct omap_dss_device *dst)
108 {
109         return 0;
110 }
111
112 static void nec_8048_disconnect(struct omap_dss_device *src,
113                                 struct omap_dss_device *dst)
114 {
115 }
116
117 static void nec_8048_enable(struct omap_dss_device *dssdev)
118 {
119         struct panel_drv_data *ddata = to_panel_data(dssdev);
120
121         gpiod_set_value_cansleep(ddata->res_gpio, 1);
122 }
123
124 static void nec_8048_disable(struct omap_dss_device *dssdev)
125 {
126         struct panel_drv_data *ddata = to_panel_data(dssdev);
127
128         gpiod_set_value_cansleep(ddata->res_gpio, 0);
129 }
130
131 static int nec_8048_get_modes(struct omap_dss_device *dssdev,
132                               struct drm_connector *connector)
133 {
134         struct panel_drv_data *ddata = to_panel_data(dssdev);
135
136         return omapdss_display_get_modes(connector, &ddata->vm);
137 }
138
139 static const struct omap_dss_device_ops nec_8048_ops = {
140         .connect        = nec_8048_connect,
141         .disconnect     = nec_8048_disconnect,
142
143         .enable         = nec_8048_enable,
144         .disable        = nec_8048_disable,
145
146         .get_modes      = nec_8048_get_modes,
147 };
148
149 static int nec_8048_probe(struct spi_device *spi)
150 {
151         struct panel_drv_data *ddata;
152         struct omap_dss_device *dssdev;
153         struct gpio_desc *gpio;
154         int r;
155
156         dev_dbg(&spi->dev, "%s\n", __func__);
157
158         spi->mode = SPI_MODE_0;
159         spi->bits_per_word = 32;
160
161         r = spi_setup(spi);
162         if (r < 0) {
163                 dev_err(&spi->dev, "spi_setup failed: %d\n", r);
164                 return r;
165         }
166
167         init_nec_8048_wvga_lcd(spi);
168
169         ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
170         if (ddata == NULL)
171                 return -ENOMEM;
172
173         dev_set_drvdata(&spi->dev, ddata);
174
175         ddata->spi = spi;
176
177         gpio = devm_gpiod_get(&spi->dev, "reset", GPIOD_OUT_LOW);
178         if (IS_ERR(gpio)) {
179                 dev_err(&spi->dev, "failed to get reset gpio\n");
180                 return PTR_ERR(gpio);
181         }
182
183         ddata->res_gpio = gpio;
184
185         ddata->vm = nec_8048_panel_vm;
186
187         dssdev = &ddata->dssdev;
188         dssdev->dev = &spi->dev;
189         dssdev->ops = &nec_8048_ops;
190         dssdev->type = OMAP_DISPLAY_TYPE_DPI;
191         dssdev->display = true;
192         dssdev->owner = THIS_MODULE;
193         dssdev->of_ports = BIT(0);
194         dssdev->ops_flags = OMAP_DSS_DEVICE_OP_MODES;
195         dssdev->bus_flags = DRM_BUS_FLAG_DE_HIGH
196                           | DRM_BUS_FLAG_SYNC_DRIVE_POSEDGE
197                           | DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE;
198
199         omapdss_display_init(dssdev);
200         omapdss_device_register(dssdev);
201
202         return 0;
203 }
204
205 static int nec_8048_remove(struct spi_device *spi)
206 {
207         struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
208         struct omap_dss_device *dssdev = &ddata->dssdev;
209
210         dev_dbg(&ddata->spi->dev, "%s\n", __func__);
211
212         omapdss_device_unregister(dssdev);
213
214         nec_8048_disable(dssdev);
215
216         return 0;
217 }
218
219 #ifdef CONFIG_PM_SLEEP
220 static int nec_8048_suspend(struct device *dev)
221 {
222         struct spi_device *spi = to_spi_device(dev);
223
224         nec_8048_spi_send(spi, 2, 0x01);
225         mdelay(40);
226
227         return 0;
228 }
229
230 static int nec_8048_resume(struct device *dev)
231 {
232         struct spi_device *spi = to_spi_device(dev);
233
234         /* reinitialize the panel */
235         spi_setup(spi);
236         nec_8048_spi_send(spi, 2, 0x00);
237         init_nec_8048_wvga_lcd(spi);
238
239         return 0;
240 }
241 static SIMPLE_DEV_PM_OPS(nec_8048_pm_ops, nec_8048_suspend,
242                 nec_8048_resume);
243 #define NEC_8048_PM_OPS (&nec_8048_pm_ops)
244 #else
245 #define NEC_8048_PM_OPS NULL
246 #endif
247
248 static const struct of_device_id nec_8048_of_match[] = {
249         { .compatible = "omapdss,nec,nl8048hl11", },
250         {},
251 };
252
253 MODULE_DEVICE_TABLE(of, nec_8048_of_match);
254
255 static struct spi_driver nec_8048_driver = {
256         .driver = {
257                 .name   = "panel-nec-nl8048hl11",
258                 .pm     = NEC_8048_PM_OPS,
259                 .of_match_table = nec_8048_of_match,
260                 .suppress_bind_attrs = true,
261         },
262         .probe  = nec_8048_probe,
263         .remove = nec_8048_remove,
264 };
265
266 module_spi_driver(nec_8048_driver);
267
268 MODULE_ALIAS("spi:nec,nl8048hl11");
269 MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
270 MODULE_DESCRIPTION("NEC-NL8048HL11 Driver");
271 MODULE_LICENSE("GPL");