Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * NEC NL8048HL11 Panel driver
0004  *
0005  * Copyright (C) 2010 Texas Instruments Inc.
0006  * Author: Erik Gilling <konkers@android.com>
0007  * Converted to new DSS device model: Tomi Valkeinen <tomi.valkeinen@ti.com>
0008  */
0009 
0010 #include <linux/module.h>
0011 #include <linux/delay.h>
0012 #include <linux/spi/spi.h>
0013 #include <linux/fb.h>
0014 #include <linux/gpio.h>
0015 #include <linux/of_gpio.h>
0016 
0017 #include <video/omapfb_dss.h>
0018 
0019 struct panel_drv_data {
0020     struct omap_dss_device  dssdev;
0021     struct omap_dss_device *in;
0022 
0023     struct omap_video_timings videomode;
0024 
0025     int data_lines;
0026 
0027     int res_gpio;
0028     int qvga_gpio;
0029 
0030     struct spi_device *spi;
0031 };
0032 
0033 #define LCD_XRES        800
0034 #define LCD_YRES        480
0035 /*
0036  * NEC PIX Clock Ratings
0037  * MIN:21.8MHz TYP:23.8MHz MAX:25.7MHz
0038  */
0039 #define LCD_PIXEL_CLOCK     23800000
0040 
0041 static const struct {
0042     unsigned char addr;
0043     unsigned char dat;
0044 } nec_8048_init_seq[] = {
0045     { 3, 0x01 }, { 0, 0x00 }, { 1, 0x01 }, { 4, 0x00 }, { 5, 0x14 },
0046     { 6, 0x24 }, { 16, 0xD7 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x55 },
0047     { 20, 0x01 }, { 21, 0x70 }, { 22, 0x1E }, { 23, 0x25 }, { 24, 0x25 },
0048     { 25, 0x02 }, { 26, 0x02 }, { 27, 0xA0 }, { 32, 0x2F }, { 33, 0x0F },
0049     { 34, 0x0F }, { 35, 0x0F }, { 36, 0x0F }, { 37, 0x0F }, { 38, 0x0F },
0050     { 39, 0x00 }, { 40, 0x02 }, { 41, 0x02 }, { 42, 0x02 }, { 43, 0x0F },
0051     { 44, 0x0F }, { 45, 0x0F }, { 46, 0x0F }, { 47, 0x0F }, { 48, 0x0F },
0052     { 49, 0x0F }, { 50, 0x00 }, { 51, 0x02 }, { 52, 0x02 }, { 53, 0x02 },
0053     { 80, 0x0C }, { 83, 0x42 }, { 84, 0x42 }, { 85, 0x41 }, { 86, 0x14 },
0054     { 89, 0x88 }, { 90, 0x01 }, { 91, 0x00 }, { 92, 0x02 }, { 93, 0x0C },
0055     { 94, 0x1C }, { 95, 0x27 }, { 98, 0x49 }, { 99, 0x27 }, { 102, 0x76 },
0056     { 103, 0x27 }, { 112, 0x01 }, { 113, 0x0E }, { 114, 0x02 },
0057     { 115, 0x0C }, { 118, 0x0C }, { 121, 0x30 }, { 130, 0x00 },
0058     { 131, 0x00 }, { 132, 0xFC }, { 134, 0x00 }, { 136, 0x00 },
0059     { 138, 0x00 }, { 139, 0x00 }, { 140, 0x00 }, { 141, 0xFC },
0060     { 143, 0x00 }, { 145, 0x00 }, { 147, 0x00 }, { 148, 0x00 },
0061     { 149, 0x00 }, { 150, 0xFC }, { 152, 0x00 }, { 154, 0x00 },
0062     { 156, 0x00 }, { 157, 0x00 }, { 2, 0x00 },
0063 };
0064 
0065 static const struct omap_video_timings nec_8048_panel_timings = {
0066     .x_res      = LCD_XRES,
0067     .y_res      = LCD_YRES,
0068     .pixelclock = LCD_PIXEL_CLOCK,
0069     .hfp        = 6,
0070     .hsw        = 1,
0071     .hbp        = 4,
0072     .vfp        = 3,
0073     .vsw        = 1,
0074     .vbp        = 4,
0075 
0076     .vsync_level    = OMAPDSS_SIG_ACTIVE_LOW,
0077     .hsync_level    = OMAPDSS_SIG_ACTIVE_LOW,
0078     .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
0079     .de_level   = OMAPDSS_SIG_ACTIVE_HIGH,
0080     .sync_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
0081 };
0082 
0083 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
0084 
0085 static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
0086             unsigned char reg_data)
0087 {
0088     int ret = 0;
0089     unsigned int cmd = 0, data = 0;
0090 
0091     cmd = 0x0000 | reg_addr; /* register address write */
0092     data = 0x0100 | reg_data; /* register data write */
0093     data = (cmd << 16) | data;
0094 
0095     ret = spi_write(spi, (unsigned char *)&data, 4);
0096     if (ret)
0097         pr_err("error in spi_write %x\n", data);
0098 
0099     return ret;
0100 }
0101 
0102 static int init_nec_8048_wvga_lcd(struct spi_device *spi)
0103 {
0104     unsigned int i;
0105     /* Initialization Sequence */
0106     /* nec_8048_spi_send(spi, REG, VAL) */
0107     for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
0108         nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
0109                 nec_8048_init_seq[i].dat);
0110     udelay(20);
0111     nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
0112                 nec_8048_init_seq[i].dat);
0113     return 0;
0114 }
0115 
0116 static int nec_8048_connect(struct omap_dss_device *dssdev)
0117 {
0118     struct panel_drv_data *ddata = to_panel_data(dssdev);
0119     struct omap_dss_device *in = ddata->in;
0120 
0121     if (omapdss_device_is_connected(dssdev))
0122         return 0;
0123 
0124     return in->ops.dpi->connect(in, dssdev);
0125 }
0126 
0127 static void nec_8048_disconnect(struct omap_dss_device *dssdev)
0128 {
0129     struct panel_drv_data *ddata = to_panel_data(dssdev);
0130     struct omap_dss_device *in = ddata->in;
0131 
0132     if (!omapdss_device_is_connected(dssdev))
0133         return;
0134 
0135     in->ops.dpi->disconnect(in, dssdev);
0136 }
0137 
0138 static int nec_8048_enable(struct omap_dss_device *dssdev)
0139 {
0140     struct panel_drv_data *ddata = to_panel_data(dssdev);
0141     struct omap_dss_device *in = ddata->in;
0142     int r;
0143 
0144     if (!omapdss_device_is_connected(dssdev))
0145         return -ENODEV;
0146 
0147     if (omapdss_device_is_enabled(dssdev))
0148         return 0;
0149 
0150     if (ddata->data_lines)
0151         in->ops.dpi->set_data_lines(in, ddata->data_lines);
0152     in->ops.dpi->set_timings(in, &ddata->videomode);
0153 
0154     r = in->ops.dpi->enable(in);
0155     if (r)
0156         return r;
0157 
0158     if (gpio_is_valid(ddata->res_gpio))
0159         gpio_set_value_cansleep(ddata->res_gpio, 1);
0160 
0161     dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
0162 
0163     return 0;
0164 }
0165 
0166 static void nec_8048_disable(struct omap_dss_device *dssdev)
0167 {
0168     struct panel_drv_data *ddata = to_panel_data(dssdev);
0169     struct omap_dss_device *in = ddata->in;
0170 
0171     if (!omapdss_device_is_enabled(dssdev))
0172         return;
0173 
0174     if (gpio_is_valid(ddata->res_gpio))
0175         gpio_set_value_cansleep(ddata->res_gpio, 0);
0176 
0177     in->ops.dpi->disable(in);
0178 
0179     dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
0180 }
0181 
0182 static void nec_8048_set_timings(struct omap_dss_device *dssdev,
0183         struct omap_video_timings *timings)
0184 {
0185     struct panel_drv_data *ddata = to_panel_data(dssdev);
0186     struct omap_dss_device *in = ddata->in;
0187 
0188     ddata->videomode = *timings;
0189     dssdev->panel.timings = *timings;
0190 
0191     in->ops.dpi->set_timings(in, timings);
0192 }
0193 
0194 static void nec_8048_get_timings(struct omap_dss_device *dssdev,
0195         struct omap_video_timings *timings)
0196 {
0197     struct panel_drv_data *ddata = to_panel_data(dssdev);
0198 
0199     *timings = ddata->videomode;
0200 }
0201 
0202 static int nec_8048_check_timings(struct omap_dss_device *dssdev,
0203         struct omap_video_timings *timings)
0204 {
0205     struct panel_drv_data *ddata = to_panel_data(dssdev);
0206     struct omap_dss_device *in = ddata->in;
0207 
0208     return in->ops.dpi->check_timings(in, timings);
0209 }
0210 
0211 static struct omap_dss_driver nec_8048_ops = {
0212     .connect    = nec_8048_connect,
0213     .disconnect = nec_8048_disconnect,
0214 
0215     .enable     = nec_8048_enable,
0216     .disable    = nec_8048_disable,
0217 
0218     .set_timings    = nec_8048_set_timings,
0219     .get_timings    = nec_8048_get_timings,
0220     .check_timings  = nec_8048_check_timings,
0221 
0222     .get_resolution = omapdss_default_get_resolution,
0223 };
0224 
0225 
0226 static int nec_8048_probe_of(struct spi_device *spi)
0227 {
0228     struct device_node *node = spi->dev.of_node;
0229     struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
0230     struct omap_dss_device *in;
0231     int gpio;
0232 
0233     gpio = of_get_named_gpio(node, "reset-gpios", 0);
0234     if (!gpio_is_valid(gpio)) {
0235         dev_err(&spi->dev, "failed to parse enable gpio\n");
0236         return gpio;
0237     }
0238     ddata->res_gpio = gpio;
0239 
0240     /* XXX the panel spec doesn't mention any QVGA pin?? */
0241     ddata->qvga_gpio = -ENOENT;
0242 
0243     in = omapdss_of_find_source_for_first_ep(node);
0244     if (IS_ERR(in)) {
0245         dev_err(&spi->dev, "failed to find video source\n");
0246         return PTR_ERR(in);
0247     }
0248 
0249     ddata->in = in;
0250 
0251     return 0;
0252 }
0253 
0254 static int nec_8048_probe(struct spi_device *spi)
0255 {
0256     struct panel_drv_data *ddata;
0257     struct omap_dss_device *dssdev;
0258     int r;
0259 
0260     dev_dbg(&spi->dev, "%s\n", __func__);
0261 
0262     if (!spi->dev.of_node)
0263         return -ENODEV;
0264 
0265     spi->mode = SPI_MODE_0;
0266     spi->bits_per_word = 32;
0267 
0268     r = spi_setup(spi);
0269     if (r < 0) {
0270         dev_err(&spi->dev, "spi_setup failed: %d\n", r);
0271         return r;
0272     }
0273 
0274     init_nec_8048_wvga_lcd(spi);
0275 
0276     ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
0277     if (ddata == NULL)
0278         return -ENOMEM;
0279 
0280     dev_set_drvdata(&spi->dev, ddata);
0281 
0282     ddata->spi = spi;
0283 
0284     r = nec_8048_probe_of(spi);
0285     if (r)
0286         return r;
0287 
0288     if (gpio_is_valid(ddata->qvga_gpio)) {
0289         r = devm_gpio_request_one(&spi->dev, ddata->qvga_gpio,
0290                 GPIOF_OUT_INIT_HIGH, "lcd QVGA");
0291         if (r)
0292             goto err_gpio;
0293     }
0294 
0295     if (gpio_is_valid(ddata->res_gpio)) {
0296         r = devm_gpio_request_one(&spi->dev, ddata->res_gpio,
0297                 GPIOF_OUT_INIT_LOW, "lcd RES");
0298         if (r)
0299             goto err_gpio;
0300     }
0301 
0302     ddata->videomode = nec_8048_panel_timings;
0303 
0304     dssdev = &ddata->dssdev;
0305     dssdev->dev = &spi->dev;
0306     dssdev->driver = &nec_8048_ops;
0307     dssdev->type = OMAP_DISPLAY_TYPE_DPI;
0308     dssdev->owner = THIS_MODULE;
0309     dssdev->panel.timings = ddata->videomode;
0310 
0311     r = omapdss_register_display(dssdev);
0312     if (r) {
0313         dev_err(&spi->dev, "Failed to register panel\n");
0314         goto err_reg;
0315     }
0316 
0317     return 0;
0318 
0319 err_reg:
0320 err_gpio:
0321     omap_dss_put_device(ddata->in);
0322     return r;
0323 }
0324 
0325 static void nec_8048_remove(struct spi_device *spi)
0326 {
0327     struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
0328     struct omap_dss_device *dssdev = &ddata->dssdev;
0329     struct omap_dss_device *in = ddata->in;
0330 
0331     dev_dbg(&ddata->spi->dev, "%s\n", __func__);
0332 
0333     omapdss_unregister_display(dssdev);
0334 
0335     nec_8048_disable(dssdev);
0336     nec_8048_disconnect(dssdev);
0337 
0338     omap_dss_put_device(in);
0339 }
0340 
0341 #ifdef CONFIG_PM_SLEEP
0342 static int nec_8048_suspend(struct device *dev)
0343 {
0344     struct spi_device *spi = to_spi_device(dev);
0345 
0346     nec_8048_spi_send(spi, 2, 0x01);
0347     mdelay(40);
0348 
0349     return 0;
0350 }
0351 
0352 static int nec_8048_resume(struct device *dev)
0353 {
0354     struct spi_device *spi = to_spi_device(dev);
0355 
0356     /* reinitialize the panel */
0357     spi_setup(spi);
0358     nec_8048_spi_send(spi, 2, 0x00);
0359     init_nec_8048_wvga_lcd(spi);
0360 
0361     return 0;
0362 }
0363 static SIMPLE_DEV_PM_OPS(nec_8048_pm_ops, nec_8048_suspend,
0364         nec_8048_resume);
0365 #define NEC_8048_PM_OPS (&nec_8048_pm_ops)
0366 #else
0367 #define NEC_8048_PM_OPS NULL
0368 #endif
0369 
0370 static const struct of_device_id nec_8048_of_match[] = {
0371     { .compatible = "omapdss,nec,nl8048hl11", },
0372     {},
0373 };
0374 
0375 MODULE_DEVICE_TABLE(of, nec_8048_of_match);
0376 
0377 static struct spi_driver nec_8048_driver = {
0378     .driver = {
0379         .name   = "panel-nec-nl8048hl11",
0380         .pm = NEC_8048_PM_OPS,
0381         .of_match_table = nec_8048_of_match,
0382         .suppress_bind_attrs = true,
0383     },
0384     .probe  = nec_8048_probe,
0385     .remove = nec_8048_remove,
0386 };
0387 
0388 module_spi_driver(nec_8048_driver);
0389 
0390 MODULE_ALIAS("spi:nec,nl8048hl11");
0391 MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
0392 MODULE_DESCRIPTION("NEC-NL8048HL11 Driver");
0393 MODULE_LICENSE("GPL");