1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * NEC NL8048HL11 Panel driver
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>
10 #include <linux/delay.h>
11 #include <linux/gpio/consumer.h>
12 #include <linux/module.h>
13 #include <linux/spi/spi.h>
15 #include "../dss/omapdss.h"
17 struct panel_drv_data {
18 struct omap_dss_device dssdev;
22 struct gpio_desc *res_gpio;
24 struct spi_device *spi;
30 * NEC PIX Clock Ratings
31 * MIN:21.8MHz TYP:23.8MHz MAX:25.7MHz
33 #define LCD_PIXEL_CLOCK 23800000
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 },
59 static const struct videomode nec_8048_panel_vm = {
62 .pixelclock = LCD_PIXEL_CLOCK,
70 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW,
73 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
75 static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
76 unsigned char reg_data)
79 unsigned int cmd = 0, data = 0;
81 cmd = 0x0000 | reg_addr; /* register address write */
82 data = 0x0100 | reg_data; /* register data write */
83 data = (cmd << 16) | data;
85 ret = spi_write(spi, (unsigned char *)&data, 4);
87 pr_err("error in spi_write %x\n", data);
92 static int init_nec_8048_wvga_lcd(struct spi_device *spi)
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);
101 nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
102 nec_8048_init_seq[i].dat);
106 static int nec_8048_connect(struct omap_dss_device *src,
107 struct omap_dss_device *dst)
112 static void nec_8048_disconnect(struct omap_dss_device *src,
113 struct omap_dss_device *dst)
117 static void nec_8048_enable(struct omap_dss_device *dssdev)
119 struct panel_drv_data *ddata = to_panel_data(dssdev);
121 gpiod_set_value_cansleep(ddata->res_gpio, 1);
124 static void nec_8048_disable(struct omap_dss_device *dssdev)
126 struct panel_drv_data *ddata = to_panel_data(dssdev);
128 gpiod_set_value_cansleep(ddata->res_gpio, 0);
131 static int nec_8048_get_modes(struct omap_dss_device *dssdev,
132 struct drm_connector *connector)
134 struct panel_drv_data *ddata = to_panel_data(dssdev);
136 return omapdss_display_get_modes(connector, &ddata->vm);
139 static const struct omap_dss_device_ops nec_8048_ops = {
140 .connect = nec_8048_connect,
141 .disconnect = nec_8048_disconnect,
143 .enable = nec_8048_enable,
144 .disable = nec_8048_disable,
146 .get_modes = nec_8048_get_modes,
149 static int nec_8048_probe(struct spi_device *spi)
151 struct panel_drv_data *ddata;
152 struct omap_dss_device *dssdev;
153 struct gpio_desc *gpio;
156 dev_dbg(&spi->dev, "%s\n", __func__);
158 spi->mode = SPI_MODE_0;
159 spi->bits_per_word = 32;
163 dev_err(&spi->dev, "spi_setup failed: %d\n", r);
167 init_nec_8048_wvga_lcd(spi);
169 ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
173 dev_set_drvdata(&spi->dev, ddata);
177 gpio = devm_gpiod_get(&spi->dev, "reset", GPIOD_OUT_LOW);
179 dev_err(&spi->dev, "failed to get reset gpio\n");
180 return PTR_ERR(gpio);
183 ddata->res_gpio = gpio;
185 ddata->vm = nec_8048_panel_vm;
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;
199 omapdss_display_init(dssdev);
200 omapdss_device_register(dssdev);
205 static int nec_8048_remove(struct spi_device *spi)
207 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
208 struct omap_dss_device *dssdev = &ddata->dssdev;
210 dev_dbg(&ddata->spi->dev, "%s\n", __func__);
212 omapdss_device_unregister(dssdev);
214 nec_8048_disable(dssdev);
219 #ifdef CONFIG_PM_SLEEP
220 static int nec_8048_suspend(struct device *dev)
222 struct spi_device *spi = to_spi_device(dev);
224 nec_8048_spi_send(spi, 2, 0x01);
230 static int nec_8048_resume(struct device *dev)
232 struct spi_device *spi = to_spi_device(dev);
234 /* reinitialize the panel */
236 nec_8048_spi_send(spi, 2, 0x00);
237 init_nec_8048_wvga_lcd(spi);
241 static SIMPLE_DEV_PM_OPS(nec_8048_pm_ops, nec_8048_suspend,
243 #define NEC_8048_PM_OPS (&nec_8048_pm_ops)
245 #define NEC_8048_PM_OPS NULL
248 static const struct of_device_id nec_8048_of_match[] = {
249 { .compatible = "omapdss,nec,nl8048hl11", },
253 MODULE_DEVICE_TABLE(of, nec_8048_of_match);
255 static struct spi_driver nec_8048_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,
262 .probe = nec_8048_probe,
263 .remove = nec_8048_remove,
266 module_spi_driver(nec_8048_driver);
268 MODULE_ALIAS("spi:nec,nl8048hl11");
269 MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
270 MODULE_DESCRIPTION("NEC-NL8048HL11 Driver");
271 MODULE_LICENSE("GPL");